The group concept in Linux is used to manage user permissions collectively, and there are several useful commands related to groups. Hereβs a breakdown to help you understand and use them:
π§° Key Linux Group Commands
π₯ 1. See Groups for Current User
groups
- Shows which groups you are a member of.
π€ 2. See Groups for Another User
groups username
Example:
groups alice
π 3. List All Groups on the System
getent group
or
cat /etc/group
β 4. Add a New Group
sudo groupadd groupname
Example:
sudo groupadd devteam
π§βπ€βπ§ 5. Add a User to a Group
sudo usermod -aG groupname username
β οΈ Make sure to use -aG (append to group), or youβll overwrite existing group memberships.
Example:
sudo usermod -aG devteam alice
The user may need to log out and back in for changes to take effect.
β 6. Remove a User from a Group
This isn’t done directly with a simple command, but you can use:
sudo gpasswd -d username groupname
Example:
sudo gpasswd -d alice devteam
π§ 7. Change a File or Folder’s Group
sudo chgrp groupname filename
Example:
sudo chgrp devteam /var/www/html
π 8. Change Group Ownership Recursively
sudo chgrp -R groupname /path/to/folder