How to add a user to a secondary group?

QuestionsQuestions8 SkillsProYour First Linux LabOct, 15 2025
0203

To add a user to a secondary group in Linux, you can use the usermod command with the -aG option. Here’s how to do it:

  1. Open the Terminal.

  2. Use the usermod Command:
    The syntax for adding a user to a secondary group is as follows:

    sudo usermod -aG groupname username
    • Replace groupname with the name of the secondary group you want to add the user to.
    • Replace username with the name of the user you want to add.
  3. Example:
    If you want to add a user named joker to a secondary group called developers, you would run:

    sudo usermod -aG developers joker
  4. Verify the Change:
    After adding the user to the secondary group, you can verify the change by using the groups command:

    groups joker

    This will show all the groups that the user joker belongs to, including the newly added secondary group.

Note: The -a option is important because it appends the user to the specified group without removing them from any other groups they are already a member of.

0 Comments

no data
Be the first to share your comment!