Part 2 of 7 · 2 min read
Users and groups
Think of a company where every employee has a number on a badge and a name on a list. The doors read the number, and the list is for people. The analogy stops in one place: a company can reissue a badge with a new number, while a user ID names the owner of files for ever.
In plain words: The kernel knows users and groups only by number. A user ID (uid) is a number, and uid 0 is the superuser, root, for whom most checks are skipped. A group ID (gid) names a set of users. A process has one user ID and one main group ID, and a list of extra groups. The file /etc/passwd maps a name to a uid, a main gid, a home directory and a login program, and /etc/group lists the groups. Programs show names, and the kernel compares numbers.
A worked example. The line for the user nobody on the test machine reads:
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
The fields are the name, a placeholder for the password (the hash lives in /etc/shadow, page 3), the uid 65534, the gid 65534, a comment, the home directory and the login program. The program /usr/sbin/nologin refuses interactive logins, so this user exists to own files and to run programs with few rights. Since the number is what counts, two machines that give the same name different numbers will disagree about who owns a file on a shared disk.
The key lines. A file stores the owner's uid and the group's gid in its inode (Level 9, page 2). The owner can change the mode. Only root can change the owner.
User ID and group ID
A user ID (uid) and a group ID (gid) are the numbers by which the kernel identifies users and groups. Each process carries them, and each file's inode stores an owner uid and a group gid. User ID 0 is the superuser, for which most permission checks do not apply.
Example: the user nobody has uid 65534 and gid 65534 on the test machine.
Check yourself: 1. What does the kernel use to identify a user? 2. What is special about uid 0? 3. Where is the password hash kept?