LinuxIV · Users, Groups and IdentityIdentity databases
/etc/passwd, /etc/shadow, /etc/group
What you'll learn
- Read every field of /etc/passwd and /etc/group
- Explain the role of /etc/shadow and its hardened permissions
- Recognise when a tool should be used instead of editing the file directly
- Audit the user database for unexpected accounts
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
Linux identity is stored in three text files: /etc/passwd, /etc/shadow, and /etc/group. Editing them directly is fragile and almost always wrong — but reading them, auditing them, and understanding them is mandatory for a sysadmin.
/etc/passwd
The classic password database. One line per user, seven colon- separated fields:
root:x:0:0:root:/root:/bin/bash
alice:x:1000:1000:Alice Smith,,,:/home/alice:/bin/bash
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
| Field | Meaning |
|---|---|
| 1 | Login name |
| 2 | Password placeholder (x — actual hash in /etc/shadow) |
| 3 | UID (user ID number) |
| 4 | Primary GID |
| 5 | GECOS field (real name, office, phone — comma-separated) |
| 6 | Home directory |
| 7 | Login shell (or /usr/sbin/nologin / /bin/false for non-login accounts) |
$ getent passwd root alice www-data nobodyroot:x:0:0:root:/root:/bin/bash
alice:x:1000:1000:Alice Smith:/home/alice:/bin/bash
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologinIllustrative output
/etc/shadow
The hardened counterpart to /etc/passwd. One line per user, nine colon-separated fields:
root:$y$j9T$...$...:19550:0:99999:7:::
alice:$y$j9T$...$...:19550:0:99999:7:::
| Field | Meaning |
|---|---|
| 1 | Login name (mirrors /etc/passwd) |
| 2 | Hashed password, or * / ! / !! to disable login |
| 3 | Date of last password change (days since 1970-01-01) |
| 4 | Minimum days between changes (0 = no minimum) |
| 5 | Maximum days between changes (99999 = effectively never) |
| 6 | Warning days before expiry |
| 7 | Account-inactive days after expiry |
| 8 | Account expiration date (days since epoch) |
| 9 | Reserved (currently unused) |
$ ls -l /etc/passwd /etc/shadow /etc/group /etc/gshadow-rw-r--r-- 1 root root 3010 Aug 9 11:11 /etc/passwd
-rw-r----- 1 root shadow 1840 Aug 9 11:11 /etc/shadow
-rw-r--r-- 1 root root 1024 Aug 9 11:11 /etc/group
-rw-r----- 1 root shadow 850 Aug 9 11:11 /etc/gshadowIllustrative output
/etc/group and /etc/gshadow
/etc/group lists every group and its members. Same one-line-per- group format as /etc/passwd:
root:x:0:
sudo:x:27:alice
adm:x:4:syslog,alice
Fields: group name, password placeholder, GID, comma-separated member list. The members list includes only users whose primary GID is NOT this group; users with this as their primary GID are listed by the lookup automatically.
/etc/gshadow (mode 0640, root:shadow) holds the group password
hash and the list of group administrators. It is rarely used in
modern systems — group membership is managed directly.
What the fields mean in production
UID ranges:
| Range | Convention | Use |
|---|---|---|
| 0 | root | The single root account |
| 1-999 | System accounts | Daemons, services. Should have /usr/sbin/nologin or /bin/false as shell. |
| 1000-60000 | User accounts | Interactive humans, depending on UID_MIN/UID_MAX in /etc/login.defs |
| 65534 | nobody | Default for unbound UIDs (NFS, container UID mapping) |
Audit commands
$ awk -F: '$3 == 0 { print $1 }' /etc/passwdrootIllustrative output
$ awk -F: '$3 < 1000 && $3 > 0 { print $1, $3, $7 }' /etc/passwd | sort -k2 -ndaemon 1 /usr/sbin/nologin
adm 3 /usr/sbin/nologin
sys 2 /usr/sbin/nologin
...Illustrative output
$ awk -F: '$7 !~ /(nologin|false|sync|halt|shutdown)/ { print $1, $7 }' /etc/passwd | headroot /bin/bash
alice /bin/bashIllustrative output
Knowledge check
Knowledge check · 3 questions
Q1. Why does /etc/passwd have an 'x' in the password field for most users?
Q2. It is safe to add a user by editing /etc/passwd and /etc/shadow with sed.
Q3. Which of the following audit commands correctly identify suspicious accounts? Select all that apply.
Passing score: 75%. Answers are checked in this browser.