Anatomy of /etc/passwd, /etc/shadow, UID Allocations & Multi-User Security Isolation
Linux is designed from its Unix roots around the principle of multi-user access control and the principle of least privilege. In Linux, every process, file, network socket, and hardware resource is strictly tagged with user and group ownership. To the kernel, users are not textual names like “admin” or “john”; they are positive 32-bit integers known as UIDs (User Identifiers).
Linux categorizes user accounts into three functional tiers according to their assigned UID numbers:
| Account Category | Standard UID Range | Role & System Purpose |
|---|---|---|
| Superuser (root) | 0 |
The almighty system administrator. Root bypasses all standard filesystem permission checks, can read or overwrite any block device, bind ports <1024, and modify kernel state. |
| System (Service) Users | 1 – 999(or 1 – 499 on older RHEL) |
Accounts created to run specific background daemons (e.g. daemon, bin, sys, www-data, mysql, sshd, systemd-resolve). These accounts do not possess interactive login shells for security isolation. |
| Regular (Human) Users | 1000 – 60000+(or 500+ on older RHEL) |
Standard interactive human users (developers, students, operators). They are assigned private home directories (/home/username) and restricted permissions. |
The /etc/passwd file is a plain-text database containing one line for every user account registered on the operating system. Because common utilities like ls -l need to map numeric UIDs to usernames, this file has world-readable permissions (644 / -rw-r--r--).
Each entry contains exactly 7 colon-delimited (:) fields:
student:x:1000:1000:Student User,Lab 204,555-0199:/home/student:/bin/bash
| Field # | Field Name | Explanation & Technical Rules |
|---|---|---|
| 1 | Username | Unique login name (case-sensitive, typically lowercase letters, 1 to 32 characters). |
| 2 | Password Placeholder | Historically contained the encrypted password hash. In modern Linux, this always contains an x, indicating that the actual password hash is protected inside /etc/shadow. |
| 3 | User ID (UID) | Unique positive integer identifying the user to the kernel scheduler and filesystem. |
| 4 | Primary Group ID (GID) | Numeric group identifier of the user's primary group (defined in /etc/group). |
| 5 | GECOS Comment | Optional informational metadata: Full Name, Room/Building, Work Phone, Home Phone. |
| 6 | Home Directory | Absolute path to the user's initial working directory upon authentication (e.g. /home/student or /root). |
| 7 | Default Login Shell | Absolute path to the shell program spawned when the user logs in (e.g. /bin/bash, /bin/zsh, or /usr/sbin/nologin). |
To eliminate password cracking risks, the encrypted password hashes were separated into /etc/shadow with strict 640 permissions owned by root:shadow (unreadable by regular users). Each record consists of 9 colon-delimited fields:
student:$6$kX9jD1...$sU8...:19665:0:90:7:14:20000:
| Field # | Parameter | Description & Values |
|---|---|---|
| 1 | Username | Must match the exact username in /etc/passwd. |
| 2 | Encrypted Hash | Composed of $ID$SALT$HASH. If it starts with ! or *, the account is locked/disabled.
• $1$ = MD5 (deprecated)
• $5$ = SHA-256
• $6$ = SHA-512 (standard across Ubuntu/RHEL)
• $y$ = Yescrypt (modern memory-hard default in Ubuntu 22.04+)
|
| 3 | Last Password Change | Days elapsed between January 1, 1970 (Unix Epoch) and the date the password was last modified. |
| 4 | Minimum Password Age | Minimum days required before user can change password again (0 = any time). |
| 5 | Maximum Password Age | Number of days password remains valid before mandatory expiration (e.g. 90 days). |
| 6 | Warning Period | Days prior to password expiration that user receives warning banners at login (e.g. 7 days). |
| 7 | Inactive Period | Days after password expiration before account is permanently disabled (grace period). |
| 8 | Account Expiration Date | Fixed absolute date (in days since Epoch) when account permanently expires regardless of password. |
| 9 | Reserved Field | Reserved for future kernel enhancements; currently blank. |
System service accounts (like www-data, nginx, postgres) exist solely to run background processes with bounded permissions. Allowing interactive shell login to service accounts would introduce severe security vulnerabilities:
/usr/sbin/nologin: The standard shell for service accounts. If an interactive SSH or console login is attempted, it prints a message (“This account is currently not available.”) and exits, logging the incident to syslog./bin/false: A dummy binary that immediately returns an exit status code of 1 and closes the connection silently.Corrupting /etc/passwd or /etc/shadow can paralyze server authentication. The pwck (Password Check) command parses both files, verifying field formats, unique UIDs, valid home directories, and syntax consistency:
# Run integrity audit on user databases (requires sudo)
sudo pwck -r
# Query user database using standard NSS resolver
getent passwd student
Terminal Lab Exercise: Open your Linux terminal and execute these safe commands to inspect user account internals:
# Step 1: View your own entry in /etc/passwd
grep "^$USER:" /etc/passwd
# Step 2: Check permissions on /etc/passwd and /etc/shadow
ls -l /etc/passwd /etc/shadow
# Notice /etc/passwd is -rw-r--r-- (readable by everyone)
# Notice /etc/shadow is -rw-r----- (readable only by root)
# Step 3: Count total regular users vs system users
echo "Total User Accounts:" $(wc -l < /etc/passwd)
echo "System Users without shell:" $(grep -E "(nologin|false)$" /etc/passwd | wc -l)
# Step 4: Run password file integrity check
sudo pwck -r
/etc/passwd must be readable by all users and utilities (such as ls) to translate numeric UIDs into usernames. If cryptographic password hashes were kept in /etc/passwd, unprivileged users could copy them for offline dictionary attacks. Therefore, password hashes are stored in /etc/shadow, accessible only to the root user.
x indicates shadow password protection: the encrypted password hash is stored in /etc/shadow rather than /etc/passwd.
/bin/false exits silently with code 1. /usr/sbin/nologin displays a message (“This account is currently not available.”) and logs the connection attempt to the system log.
$6$ denotes the SHA-512 hashing algorithm (standard for many years). $y$ denotes the modern Yescrypt algorithm, which provides memory-hard protection against GPU and ASIC brute-force attacks.
pwck (Password Check) command verifies entry syntax, valid UIDs, unique names, and accessible home directories across both files.
getent passwd username. The getent utility queries the Name Service Switch (NSS), fetching records from local files (/etc/passwd) as well as network identity sources (LDAP, SSSD, Winbind).
useradd -o -u 0 aliasname). However, this creates a severe security risk and audit confusion because the kernel treats them as the identical security principal, making logs ambiguous.
sudo passwd -l username (or sudo usermod -L username). This prepends ! to the password hash in /etc/shadow, locking password access.
sudo passwd -u username (or sudo usermod -U username). This removes the leading ! character from /etc/shadow.
/etc/default/useradd, /etc/login.defs, and the skeleton directory /etc/skel/.
nobody user (UID 65534) is an unprivileged user account used by services (like NFS) to run processes that require absolute minimal system permissions and own zero permanent files.