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:
-
Check Current Groups: First, check the current groups the user belongs to using the
groupscommand:groups username -
Add User to Additional Groups: Use the
usermodcommand with the-aGoption to add the user to one or more groups. For example, to add the userusernameto the groupsgroup1andgroup2, you would run:sudo usermod -aG group1,group2 username -
Verify Group Membership: After adding the user to the groups, you can verify the changes by running the
groupscommand again:groups username
This will show all the groups the user is now a member of.
