How do I change a primary group?

QuestionsQuestions4 SkillsProYour First Linux LabOct, 15 2025
0273

To change a user's primary group in Linux, you can use the usermod command. Here’s how to do it:

  1. Open the Terminal.

  2. Use the usermod Command: The syntax for changing a primary group is as follows:

    sudo usermod -g new_primary_group username
    
    • Replace new_primary_group with the name of the group you want to set as the new primary group.
    • Replace username with the name of the user whose primary group you want to change.
  3. Example: If you want to change the primary group of a user named labex to a group called developers, you would run:

    sudo usermod -g developers labex
    
  4. Verify the Change: After changing the primary group, you can verify the change by using the id command:

    id labex
    

    This will show the user’s UID, primary GID, and all groups the user belongs to.

Note: You need to have superuser privileges to change a user's primary group, which is why sudo is used.

0 Comments

no data
Be the first to share your comment!