
In Linux, managing user groups is essential for organizing users and controlling permissions. This guide will walk you through creating a group, adding users to it, and managing group permissions.
Viewing Group Membership
To view the groups a user belongs to or to see the groups of the current user, you can use the groups
command:
To view groups of a specific user (replace exampleuser with the username):
groups exampleuser
To view groups of the current user:
groups
Creating a Group
To create a new group, you can use the groupadd
command:
Create a new group (replace sharedgroup with your desired group name):
sudo groupadd sharedgroup
Adding Users to a Group
To add users to a group, you can use the usermod
command:
Add a user to a group (replace examplegroup and exampleusername with the group and user names):
sudo usermod -a -G examplegroup exampleusername
Assigning Permissions to a Directory
You can assign permissions to a directory for a specific group using the chown
command:
Assign permissions to a directory for a group (replace examplegroup and sharedfolder with the group and directory names):
sudo chown -R :examplegroup sharedfolder/
Removing a User from a Group
To remove a user from a group, you can use the gpasswd
command:
Remove a user from a group (replace testuser and testgroup with the user and group names):
sudo gpasswd -d testuser testgroup
Leave a Reply