Linux basics part – 2
![](https://redientsecurity.in/wp-content/uploads/2022/07/linux-300x158.png)
Creating Users in Linux
Let’s create a user, open your terminal in linux
$ sudo adduser <username>
Example:-
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-13-44-37-1024x281.png)
Now login created user
$ sudo su – <username>
Example:-
$ sudo su – pramod
$ whoami
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-13-49-30-1024x68.png)
What is Group in Linux?
Group is a generally a collection of users. In Linux, we can create the user accounts for users and add them in a different groups according to their role and set a privileges on them.
Instead of setting the privileges on users, create a group and set a privileges on that group and add users in that group. So, its save your time.
In Linux, there are two types of Groups
- Primary – primary group is create when we create user and remember primary group’s username and group name is same.
- Secondary – Secondary group is like existing group. for example, we have System Admin group, if we add a new user then the System Admin groups privileges automatically applied on new user.
Creating Groups in Linux
Let’s create Groups in Linux
$ sudo groupadd <group-name>
In below example, i have created one group named redient-security
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-15-26-11-1024x124.png)
Here,
redient-security | name of group |
x | group password |
1002 | group id |
Adding Users in group
$ sudo usermod -a -G <groupname> <username>
Here -a is append means adding and G is for Secondary group
For example
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-15-58-43-1024x77.png)
Adding Users in Multiple groups
In Linux, we can add one user in multiple groups.
$ sudo usermod -a -G <group-name>,<group-name> <username>
For example:-
$ sudo usermod -a -G redient-security,sredient pramod
Adding Multiple users in a group
$ sudo usermod -a -G <groupname> <username>
In below example, i have added redient and pramod users in redient-security group
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-16-43-18-1024x79.png)
Removing User from group
gpasswd is used to remove user from a group with -d option.
$ sudo gpasswd -d <username> <groupname>
For example:-
$ sudo gpasswd -d pramod sredient
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-16-34-11-1024x70.png)
Create New User and add in Existing group in one commands
$ sudo useradd -g users -G redient-security,sredient kovid
![](https://redientsecurity.in/wp-content/uploads/2022/07/Screenshot-from-2022-07-12-17-03-18-1024x73.png)
here, -g is primary group, users is primary group name, -G option is for secondary group, redient-security and sredient is secondary group name and kovid is new user name