How can a user belong to multiple groups in Linux?

A user can belong to multiple groups in Linux by using the usermod command to add them to additional groups. Here’s how you can do it:

  1. Check Current Groups: First, check the current groups the user belongs to using the groups command:

    groups username
  2. Add User to Additional Groups: Use the usermod command with the -aG option to add the user to one or more groups. For example, to add the user username to the groups group1 and group2, you would run:

    sudo usermod -aG group1,group2 username
  3. Verify Group Membership: After adding the user to the groups, you can verify the changes by running the groups command again:

    groups username

This will show all the groups the user is now a member of.

0 Comments

no data
Be the first to share your comment!