A2oz

How Do I Change a User Group in Linux?

Published in Linux System Administration 2 mins read

You can change a user's group in Linux using the usermod command. This command allows you to modify user account properties, including the primary group.

Here's a breakdown of the process:

Changing a User's Primary Group

  1. Open a terminal: Access the command line interface.
  2. Use the usermod command:
    • Syntax: sudo usermod -G <new_group> <username>
    • Example: sudo usermod -G sudoers john This will change the primary group of the user 'john' to 'sudoers'.

Adding a User to a Secondary Group

  1. Use the usermod command:
    • Syntax: sudo usermod -aG <group_name> <username>
    • Example: sudo usermod -aG audio john This will add the user 'john' to the 'audio' group.

Removing a User from a Group

  1. Use the gpasswd command:
    • Syntax: sudo gpasswd -d <username> <group_name>
    • Example: sudo gpasswd -d john audio This will remove the user 'john' from the 'audio' group.

Important Considerations

  • Superuser privileges: You'll need root privileges (sudo) to modify user groups.
  • Group existence: Ensure the group you're adding the user to already exists.
  • Group membership: Changing a user's group can affect their permissions and access to system resources.

Remember to verify the changes you've made by checking the user's group membership using the id command: id <username>.

Related Articles