To add a user to new group we need to do 2 things.
- Create a new group
- Then add user new group
Creating new group:
We can create new group with groupadd command as shown below
$ groupadd <groupName>
Here I am considering new groupName as super and creating group.
$ groupadd super
Adding user to new group:
Before adding user to new group, list the groups in which groups the username is available.
$ groups <userName>
Here I am considering user name as gust and I will add guest user to group super.
$ groups guest
Output:
guest : guest
Here guest user is only listed guest group.
Now add guest user to super group.
$ usermod -G super,guest guest
Again list the groups of guest user with groups.
$ groups guest
Output:
guest: guest super
We can also list group names of the user listed with id command.
$ id <userName> $ id guest
-Sany