Skip to main content
RunBook Academy

LinuxIV · Users, Groups and IdentityIdentity databases

/etc/passwd, /etc/shadow, /etc/group

Foundation⏱ ~10 minbashgetentcatawkgrep

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

Not yet marked complete on this device.

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
FieldMeaning
1Login name
2Password placeholder (x — actual hash in /etc/shadow)
3UID (user ID number)
4Primary GID
5GECOS field (real name, office, phone — comma-separated)
6Home directory
7Login shell (or /usr/sbin/nologin / /bin/false for non-login accounts)
Read-only / Safegetent passwd
$ getent passwd root alice www-data nobody
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

Illustrative 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:::
FieldMeaning
1Login name (mirrors /etc/passwd)
2Hashed password, or * / ! / !! to disable login
3Date of last password change (days since 1970-01-01)
4Minimum days between changes (0 = no minimum)
5Maximum days between changes (99999 = effectively never)
6Warning days before expiry
7Account-inactive days after expiry
8Account expiration date (days since epoch)
9Reserved (currently unused)
Read-only / Safepermissions
$ 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/gshadow

Illustrative 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:

RangeConventionUse
0rootThe single root account
1-999System accountsDaemons, services. Should have /usr/sbin/nologin or /bin/false as shell.
1000-60000User accountsInteractive humans, depending on UID_MIN/UID_MAX in /etc/login.defs
65534nobodyDefault for unbound UIDs (NFS, container UID mapping)

Audit commands

Read-only / Safeaudit UID 0
$ awk -F: '$3 == 0 { print $1 }' /etc/passwd
root

Illustrative output

Read-only / Safeaudit system accounts
$ awk -F: '$3 < 1000 && $3 > 0 { print $1, $3, $7 }' /etc/passwd | sort -k2 -n
daemon 1 /usr/sbin/nologin
adm 3 /usr/sbin/nologin
sys 2 /usr/sbin/nologin
...

Illustrative output

Read-only / Safeaudit login shells
$ awk -F: '$7 !~ /(nologin|false|sync|halt|shutdown)/ { print $1, $7 }' /etc/passwd | head
root /bin/bash
alice /bin/bash

Illustrative output

Knowledge check

Knowledge check · 3 questions

  1. Q1. Why does /etc/passwd have an 'x' in the password field for most users?

  2. Q2. It is safe to add a user by editing /etc/passwd and /etc/shadow with sed.

  3. Q3. Which of the following audit commands correctly identify suspicious accounts? Select all that apply.

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