How to change primary group?

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

sudo usermod -g new_primary_group username

Breakdown of the command:

  • sudo: Runs the command with root privileges.
  • usermod: The command used to modify user accounts.
  • -g new_primary_group: Specifies the new primary group.
  • username: The name of the user whose primary group you want to change.

Example:

If you want to change the primary group of a user named "john" to "developers", you would run:

sudo usermod -g developers john

After executing this command, you can verify the change by checking the user's details with:

id john

This will display the user ID and the groups the user belongs to, including the new primary group.

0 Comments

no data
Be the first to share your comment!