Chapter Five

Users, Groups, and Permissions

How Linux decides who can read, write, and execute — from the three permission bits through ACLs and the sudo and PAM machinery behind every login.

6 topics

Every file access on a Linux server passes one check: does this process, running as some user with some set of groups, have the rights the operation needs? This chapter covers the machinery behind that check, starting with the UIDs and GIDs that identify accounts and ending with the privilege-escalation paths that let a non-root user run a single command as root.

The classic model is three permission bits — read, write, execute — applied to owner, group, and everyone else, and it covers most cases. Where it falls short, ACLs grant per-user rights, the setuid and setgid bits change which identity a process runs as, and sudo with PAM gates who may become root and how. By the end you should be able to read any ls -l line, fix a "permission denied" without resorting to chmod 777, and reason about what an attacker gains from a setuid binary.

Who gets which access
Owner (u)
The user that owns the file. The kernel checks this triad first; if you are the owner, only the owner bits apply — group and other are not added on top.
Group (g)
The file's group. Checked only if you are not the owner but belong to the group. Supplementary group membership is how shared access is granted.
Other (o)
Everyone else. The last fallback triad. A too-generous "other" is how files end up world-readable or world-writable by accident.

Topics in This Chapter

Topic 24
Users and Groups
UIDs, GIDs, and the accounts behind them. How /etc/passwd, /etc/shadow, and /etc/group define identity, what useradd and usermod do, and why a primary group differs from a supplementary one.
AccountsIdentity
Topic 25
Permission Bits and umask
The read, write, and execute bits across owner, group, and other, the octal notation chmod speaks, and how umask subtracts default permissions from every file a process creates — including why x on a directory means traverse, not run.
Permissionschmod
Topic 26
Ownership
Every file carries an owning user and group, and ownership decides which permission triad applies. chown, chgrp, the symlink traps in recursive changes, and why only root can give a file away.
chownFiles
Topic 27
setuid, setgid, and the Sticky Bit
The three special bits that bend the rules: setuid runs a binary as its owner, setgid controls group identity and inheritance, and the sticky bit keeps /tmp from becoming a free-for-all. A classic privilege-escalation surface.
Special BitsSUID
Topic 28
Access Control Lists
When owner-group-other is too coarse, POSIX ACLs grant named users and groups their own rights. getfacl, setfacl, the mask that caps effective permissions, and default ACLs that new files inherit.
ACLssetfacl
Topic 29
sudo, su, and PAM
The two paths to root and the framework that gates them: su swaps your whole shell, sudo authorizes single commands through /etc/sudoers with a log of who ran what, and PAM decides what counts as a valid login.
sudoPAM