Key Linux group commands

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

 

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top