Linux Group Management and Permissions Explained

Linux group management: primary vs supplementary groups, groupadd, usermod -aG, gpasswd, setgid shared folders, ACLs and auditing group access.

Aug 2, 2025 - 12:23
Nov 11, 2026 - 10:13
 0  59
Linux Group Management and Permissions Explained

Group management in Linux means creating groups, adding users to them and assigning groups to files so several people share access without sharing accounts. Every file has one owning group, and the middle set of rwx bits in its permissions applies to members of that group. Supplementary groups, the setgid bit and ACLs extend the model for shared folders.

This guide focuses on groups: how Linux decides group membership, the commands that change it, and the patterns for shared project directories. For the basics of rwx bits, read why read, write and execute permissions matter. For the wider RHEL setup this fits into, see our RHEL 10 first-time setup guide.

Key takeaways

  • Each user has one primary group (stored in /etc/passwd) and any number of supplementary groups (listed in /etc/group).
  • New files take the creator's primary group, unless the directory has the setgid bit, in which case they take the directory's group.
  • usermod -G without -a replaces a user's supplementary groups. Always use usermod -aG to add.
  • Group changes apply to new login sessions. Running shells keep their old group list until the user logs in again or uses newgrp.
  • ACLs let you grant a second or third group access to the same file without changing its owning group.
  • Group passwords and newgrp are rarely needed on modern systems. sudo rules and ACLs cover most cases.

How Linux checks group permissions

When a process opens a file, the kernel compares the process credentials with the file's owner and group. In order:

  1. If the process's user ID matches the file owner, the owner bits apply.
  2. Otherwise, if the file's group matches the process's group ID or any of its supplementary group IDs, the group bits apply.
  3. Otherwise the "other" bits apply.

Only one class applies. If you are the owner and the owner bits deny write, you do not fall through to the group bits even if they allow it. This catches people out when they own a file with r--rw---- permissions and cannot write to it.

With ACLs present, named user and named group entries are checked too, limited by the ACL mask. We cover that below.

The files behind groups

FileWhat it holds for groupsExample line
/etc/passwdThe user's primary group ID (4th field)asha:x:1001:1001::/home/asha:/bin/bash
/etc/groupGroup name, GID and supplementary membersdevops:x:2001:asha,ravi
/etc/gshadowGroup password hash, group admins and membersdevops:!::asha,ravi

A user is not listed in /etc/group for their primary group. That is normal: membership comes from the GID in /etc/passwd. For more on the user side of these files, see /etc/passwd vs /etc/shadow. Never edit these files by hand on a live system. Use the commands below, or vigr if you must edit, because it locks the file.

Primary vs supplementary groups

Most distributions, including RHEL, Fedora and Ubuntu, create a private group with the same name as each new user and make it the primary group. This is called the user private group scheme. It means files a user creates are not readable by a shared group by default, and teams share access through supplementary groups instead.

$ id asha
uid=1001(asha) gid=1001(asha) groups=1001(asha),2001(devops),10(wheel)

Here gid=1001(asha) is the primary group. devops and wheel are supplementary. On RHEL, membership in wheel grants sudo through the default sudoers file, so treat that group as privileged. Our guide on securing sudo access covers this.

Group management commands

TaskCommandNotes
Create a groupgroupadd devopsAdd -g 2001 to set a fixed GID across servers
Create a system groupgroupadd -r appsvcGID from the system range, for services
Rename a groupgroupmod -n platform devopsFiles keep the GID, so they follow the new name
Delete a groupgroupdel platformFails if it is a user's primary group
Add user to a groupusermod -aG devops asha-a appends; without it, other supplementary groups are removed
Add or remove one membergpasswd -a ravi devops / gpasswd -d ravi devopsChanges one membership only
Set the full member listgpasswd -M asha,ravi devopsReplaces the list
Delegate group admingpasswd -A asha devopsasha can then add and remove members
Change primary groupusermod -g devops ashaFiles in home are updated; others must be fixed by hand
List membersgetent group devopsWorks with LDAP and SSSD users too
Show a user's groupsid asha or groups asha

The usermod man page is explicit: with -G, if the user is in a group that is not listed, the user is removed from it, and -a changes that to append. Forgetting -a is one of the most common ways admins accidentally remove someone from wheel.

Why the new group does not work yet

Group membership is read at login and attached to the session's processes. After usermod -aG docker asha, asha's existing shell still has the old list, which you can confirm with id (no username) in that shell. Options:

  • Log out and back in, or start a new SSH session.
  • Run newgrp devops to start a subshell with that group as the primary group.
  • Restart services that run as the user so they pick up the change.

Assigning groups to files

# change the owning group
chgrp devops /srv/releases/build.log

# change owner and group together
chown asha:devops /srv/releases/build.log

# give the group read and write, nothing for others
chmod 660 /srv/releases/build.log
ls -l /srv/releases/build.log
-rw-rw----. 1 asha devops 2048 Nov  7 10:15 /srv/releases/build.log

A regular user can chgrp a file they own only to a group they belong to. Only root can give files away to another owner.

Shared project directories with setgid

The classic problem: three developers share /srv/project. Each new file gets the creator's private group, so the others cannot edit it. The fix is the setgid bit on the directory. New files and subdirectories then inherit the directory's group, and new subdirectories inherit the setgid bit too.

groupadd -g 2001 devops
mkdir -p /srv/project
chgrp devops /srv/project
chmod 2770 /srv/project      # 2 = setgid, 770 = rwx for owner and group
ls -ld /srv/project
drwxrws---. 2 root devops 6 Nov  7 10:20 /srv/project

The s in the group execute position shows setgid. Two more details make this work well:

  • umask. With the common umask of 022, new files are rw-r--r--, so group members can read but not write. Users who share directories usually set umask 002, which RHEL applies to users in their own private group when the UID and GID match.
  • Deletion. Anyone with write permission on the directory can delete any file in it. Add the sticky bit (chmod 3770) if users should delete only their own files.

We explain these special bits in SUID, SGID and the sticky bit.

ACLs for more than one group

Standard permissions allow one owning group. When a second team, say qa, needs read access to the same directory, use POSIX ACLs. The filesystem must support them; XFS and ext4 on current RHEL and Ubuntu do by default.

# give qa read and execute on the directory
setfacl -m g:qa:rx /srv/project

# default ACL so new files and directories inherit it
setfacl -d -m g:qa:rx /srv/project

# view ACLs
getfacl /srv/project

# remove the qa entry, or all extended entries
setfacl -x g:qa /srv/project
setfacl -b /srv/project

A + at the end of the ls -l permission string means an ACL is present. The ACL mask sets the maximum rights for named users and named groups. If someone runs chmod 750 on the directory later, the mask becomes r-x and may cut ACL rights they did not expect. Check with getfacl and look for #effective: comments.

Choosing the right tool

NeedUse
One team shares a folderGroup plus setgid directory plus umask 002
Two or more teams need different accessOwning group plus ACL entries
Users need to run admin commandssudo rules for a group, not group file permissions
A service needs access to a socket or deviceA dedicated system group, such as the one created for a container runtime
Users must only see their own filesPrivate groups and mode 700 or 750 homes

Groups in DevOps work

  • The docker group. Members of the docker group can talk to the Docker daemon socket. Docker's own documentation warns this grants root-level privileges on the host, so add only trusted users or use rootless mode.
  • Consistent GIDs. When servers share NFS storage, give groups the same GID everywhere, or files will show the wrong group on some hosts. Set GIDs explicitly with groupadd -g, manage them through configuration management, or use a central directory (LDAP, FreeIPA, Active Directory via SSSD).
  • Automation. Ansible's ansible.builtin.group and ansible.builtin.user modules (with groups: and append: true) do the same as groupadd and usermod -aG, idempotently.
  • Containers. Inside a container, file access to mounted volumes still uses numeric UIDs and GIDs. A GID that means devops on the host may mean nothing in the container.
- name: Ensure devops group exists
  ansible.builtin.group:
    name: devops
    gid: 2001
    state: present

- name: Add asha to devops without removing other groups
  ansible.builtin.user:
    name: asha
    groups: devops
    append: true

Auditing group access

# who is in privileged groups
getent group wheel sudo docker

# files owned by a group that should no longer exist
find / -xdev -nogroup 2>/dev/null

# group-writable files under a path
find /srv -xdev -type f -perm -g=w -ls

Review membership of wheel, sudo, docker and any application admin group on a schedule, and remove people when they change roles. For a broader list of controls, see 12 Linux permission controls for DevOps engineers.

Troubleshooting checklist

  1. Run id in the user's actual session, not id username, to see the groups the process has.
  2. Check every directory on the path for execute (x) permission with namei -l /full/path.
  3. Check whether the user is the owner, since owner bits win over group bits.
  4. Look for ACLs (+ in ls -l) and the effective mask.
  5. On RHEL, rule out SELinux denials with ausearch -m avc -ts recent.

Learn Linux administration hands-on

Group management is part of the RHCSA objectives. Our RHCSA training in Pune and Linux admin course (classroom in Kharadi and live online) practise users, groups, permissions, ACLs and SELinux on RHEL. The RHEL 10 user management guide pairs well with this article.

FAQ

What is the difference between a primary and a supplementary group?

The primary group is stored in /etc/passwd and becomes the group of new files. Supplementary groups are listed in /etc/group and give extra access.

How do I add a user to a group without removing other groups?

Use usermod -aG groupname username, or gpasswd -a username groupname. Plain usermod -G replaces the whole supplementary list.

Why does a new group membership not take effect?

Groups are set at login. Log out and back in, open a new SSH session, or run newgrp groupname to get a shell with that group.

How do I make new files in a shared folder belong to the team group?

Set the setgid bit on the directory with chmod 2770 and chgrp it to the team group. Pair it with umask 002 so files are group-writable.

When should I use ACLs instead of groups?

When more than one group needs different access to the same file or directory. Standard permissions allow only one owning group.

Is adding a user to the docker group safe?

Treat it like granting root. Docker documents that docker group members get root-level privileges on the host. Prefer rootless mode or sudo rules.

How do I see all members of a group?

Run getent group groupname. Remember users whose primary group is that group do not appear in the member list.

References

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.