Skip to main content
RunBook Academy

LinuxIV · Users, Groups and IdentityIdentity

UIDs, GIDs, and supplementary groups

Foundation⏱ ~10 minbashidgroupsgpasswdusermod

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

Not yet marked complete on this device.

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:

AttributeMeaning
Real UIDThe UID of the user who started the process
Effective UIDThe UID the kernel uses for permission checks (after setuid/setgid transitions)
Saved set-UIDThe UID a setuid binary can revert to
Filesystem UIDUsed by NFS for permission checks (usually equals effective UID)
Real GIDPrimary GID of the user who started the process
Effective GIDGID used for permission checks
Supplementary groupsAdditional GIDs the process is a member of
Read-only / Safeid
$ id
uid=1000(alice) gid=1000(alice) groups=1000(alice),4(adm),27(sudo),100(users)

Illustrative output

Read-only / Safeid for another user
$ id www-data
uid=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.

Read-only / Safeeffective access via supplementary group
$ stat -c '%U %G %a %n' /var/log/syslog; id -G alice
root adm 0640 /var/log/syslog
1000 4 27 100

Illustrative output

Adding users to supplementary groups

Configuration changeusermod -aG
$ sudo usermod -aG docker alice; id alice; groups alice
uid=1000(alice) gid=1000(alice) groups=1000(alice),4(adm),27(sudo),100(users),999(docker)
alice adm sudo users docker

Illustrative output

Configuration changegpasswd
$ sudo gpasswd -a alice docker; getent group admins

Illustrative output

Common group conventions

GroupPurpose
rootUID 0
wheel (RHEL-family) or sudo (Debian-family)Members may use sudo
admMembers may read logs in /var/log
usersAll human users (sometimes)
dockerMembers may use the Docker socket without sudo
kvmMembers may use /dev/kvm
systemd-journalMembers may read the system journal
  1. **Always use -aG or gpasswd -a.** Never usermod -G without -a
  2. Audit sudo/sudoers groups quarterly. Membership should be intentional and reviewed
  3. Prefer group membership over per-file ACLs. Group membership scales; per-file ACLs sprawl
  4. 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

Configuration changenewgrp
$ newgrp docker; id
uid=1000(alice) gid=1000(alice) groups=1000(alice),4(adm),27(sudo),100(users),999(docker)

Illustrative output

Knowledge check

Knowledge check · 3 questions

  1. Q1. What does `usermod -G docker alice` do without the `-a` flag?

  2. Q2. The kernel checks supplementary groups when evaluating file permissions.

  3. Q3. Which of the following statements about identity are correct? Select all that apply.

Passing score: 75%. Answers are checked in this browser.