LinuxIV · Users, Groups and IdentityIdentity
UIDs, GIDs, and supplementary groups
What you'll learn
- Distinguish UID from GID and primary group from supplementary groups
- Read effective UID/GID with id and getfacl
- Add a user to a supplementary group without breaking their existing memberships
- Audit why a user has access to a file or directory
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09
When a process opens a file, the kernel does not check “is the user called alice allowed?”. It checks “is the user’s UID in the file’s ACL?”. The names are for humans; the numbers are for the kernel.
UID and GID
Every process on the system has:
| Attribute | Meaning |
|---|---|
| Real UID | The UID of the user who started the process |
| Effective UID | The UID the kernel uses for permission checks (after setuid/setgid transitions) |
| Saved set-UID | The UID a setuid binary can revert to |
| Filesystem UID | Used by NFS for permission checks (usually equals effective UID) |
| Real GID | Primary GID of the user who started the process |
| Effective GID | GID used for permission checks |
| Supplementary groups | Additional GIDs the process is a member of |
$ iduid=1000(alice) gid=1000(alice) groups=1000(alice),4(adm),27(sudo),100(users)Illustrative output
$ id www-datauid=33(www-data) gid=33(www-data) groups=33(www-data)Illustrative output
Primary vs supplementary
A user has one primary group (the GID in /etc/passwd) and zero or more supplementary groups (the comma-separated list in /etc/group, plus groups managed by LDAP/SSSD).
The kernel checks supplementary groups when evaluating file permissions — if a file is group-readable and the user’s primary GID does not match the file’s group, the kernel checks every supplementary group.
$ stat -c '%U %G %a %n' /var/log/syslog; id -G aliceroot adm 0640 /var/log/syslog
1000 4 27 100Illustrative output
Adding users to supplementary groups
$ sudo usermod -aG docker alice; id alice; groups aliceuid=1000(alice) gid=1000(alice) groups=1000(alice),4(adm),27(sudo),100(users),999(docker)
alice adm sudo users dockerIllustrative output
$ sudo gpasswd -a alice docker; getent group adminsIllustrative output
Common group conventions
| Group | Purpose |
|---|---|
root | UID 0 |
wheel (RHEL-family) or sudo (Debian-family) | Members may use sudo |
adm | Members may read logs in /var/log |
users | All human users (sometimes) |
docker | Members may use the Docker socket without sudo |
kvm | Members may use /dev/kvm |
systemd-journal | Members may read the system journal |
- **Always use
-aGorgpasswd -a.** Neverusermod -Gwithout-a - Audit sudo/sudoers groups quarterly. Membership should be intentional and reviewed
- Prefer group membership over per-file ACLs. Group membership scales; per-file ACLs sprawl
- Document custom groups. A group called "deploy" is meaningful; a group called "g1234" is not
The effective UID and root
A process running as root has effective UID 0. The kernel treats UID 0 as “may do anything” subject to capability checks, LSM checks (SELinux, AppArmor), and seccomp filters. The difference between “process has UID 0” and “process has CAP_NET_BIND_SERVICE but otherwise is unprivileged” is the difference between a service that owns the entire machine and one that can only bind to a port.
What newgrp does
$ newgrp docker; iduid=1000(alice) gid=1000(alice) groups=1000(alice),4(adm),27(sudo),100(users),999(docker)Illustrative output
Knowledge check
Knowledge check · 3 questions
Q1. What does `usermod -G docker alice` do without the `-a` flag?
Q2. The kernel checks supplementary groups when evaluating file permissions.
Q3. Which of the following statements about identity are correct? Select all that apply.
Passing score: 75%. Answers are checked in this browser.