How do I change a user's primary group?

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

Syntax

sudo usermod -g new_primary_group username

Steps

  1. Open Terminal: Access your terminal.

  2. Run the Command: Replace new_primary_group with the name of the group you want to set as the new primary group and username with the name of the user whose primary group you want to change. For example, to change the primary group of user jack to developers, you would run:

    sudo usermod -g developers jack
  3. Verify the Change: You can check if the change was successful by using the id command:

    id jack

    This will show the user ID, primary group, and any secondary groups associated with jack.

Important Notes

  • Ensure that the new primary group already exists. You can create a new group using:
    sudo groupadd new_primary_group
  • Changing a user's primary group does not affect their membership in secondary groups.

This command is a straightforward way to manage user permissions and access based on group memberships. If you have any further questions or need additional examples, feel free to ask!

0 Comments

no data
Be the first to share your comment!