Skip to content

Adding User in Secondary Group using Command in Linux

Adding User in Secondary Group using Command in Linux Systems. This Command will add and existing user to a secondary group.

On this page

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

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

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


Back to top