Skip to content

Adding User in Secondary Group using Command in Linux

Advertisement

Secondary groups are the groups that users added after the creations. The primary groups are created during the user creation process. In order to the permissions, there is no difference between them.

This quick tutorial helps you to add an existing user to a secondary group in Linux via the command line.

Example

Use the usermod command-line tool to assign a user to a secondary group. Here you can define multiple group names separate them by a comma.

The following command will add jack to sudo group.

usermod -a -G sudo jack 

To make sure, check the entry in /etc/group file.

cat /etc/group | grep "sudo" 

Remove User from Secondary Group

If in case, you have accidentally added a user to a different group or you want to remove another user from the group. The following command will remove user "jack" from the group "sudo".

sudo gpasswd  -d jack sudo 

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top