Add or Remove User From Group in Linux

Add or Remove User From Group in Linux

In Linux system, a group is a collection of users which have the same permissions on files and directories. When working as system administrator, might need to add or remove user from group. This tutorial shows how to do that in Linux.

Add user to group

The usermod command can be used for modifying existing user details. In order to add user to a secondary group, use -a and -G option. For example, the following command adds james user to test-group group:

sudo usermod -a -G test-group james

In order to add user to multiple secondary groups at once, separate groups by comma as follows:

sudo usermod -a -G test-group,test-group2 james

Check user groups:

groups james

Remove user from group

To remove a user from a group, use the gpasswd command with -d option. For example, the following command removes james user from test-group group:

sudo gpasswd -d james test-group

Change user's primary group

Primary group of the user can be changed using usermod command with -g option.

sudo usermod -g test-group james

Leave a Comment

Cancel reply

Your email address will not be published.