Linux add user to new group

 

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s