The file /etc/passwd lists every user account on a Linux system, one per line, with the user name, numeric IDs, home directory and login shell. The file /etc/shadow holds the matching password hashes and password aging rules, and only root can read it. Splitting the two is why etc passwd etc shadow is a classic security topic: the account list must be readable by everyone, while the secrets must not be.
This guide explains each field, shows how to read both files safely, and covers the pitfalls when you edit them.
/etc/passwd
/etc/shadow
Many ordinary programs, such as ls -l, need to turn the number 1000 into the name alice. To do that they read /etc/passwd, so the file has to be world-readable. In early Unix systems the password hash lived in that same file, which meant any local user could copy the hashes and try to crack them offline.
The fix was shadow passwords: the hash moved to /etc/shadow, readable only by root (and, on some systems, the shadow group). The password field in /etc/passwd now contains just x, meaning "look in shadow". Check the permissions on your own system:
On some distributions /etc/shadow is mode 0000 or 0640, but ordinary users never have read access.
/etc/passwdEach line has seven fields separated by colons:
| Position | Example | Meaning |
|---|---|---|
| 1 | alice | Login name |
| 2 | x | Password placeholder; the real hash is in /etc/shadow |
| 3 | 1000 | User ID (UID) |
| 4 | 1000 | Primary group ID (GID) |
| 5 | Alice Smith,,, | GECOS field: full name and optional contact details |
| 6 | /home/alice | Home directory |
| 7 | /bin/bash | Login shell |
Typical UID ranges are set in /etc/login.defs. UID 0 is root, low numbers (below 1000 on most distributions) are system accounts for services such as www-data, and ordinary users start at 1000. System accounts usually have a shell like /usr/sbin/nologin so nobody can log in as them interactively.
You can inspect the file with ordinary text tools:
To list only accounts that can log in with a real shell:
Prefer getent passwd over reading the file directly. It queries every configured source (local files, LDAP, SSSD and others), so it also finds network accounts:
/etc/shadowEach line in /etc/shadow has nine colon-separated fields:
| Position | Meaning |
|---|---|
| 1 | Login name, matching /etc/passwd |
| 2 | Password hash, or a locked or disabled marker |
| 3 | Date of last password change, in days since 1 January 1970 |
| 4 | Minimum days between changes (0 means no minimum) |
| 5 | Maximum days a password stays valid (99999 means effectively never) |
| 6 | Days of warning before the password expires |
| 7 | Days after expiry before the account is disabled |
| 8 | Account expiry date, in days since 1 January 1970 |
| 9 | Reserved, normally empty |
The chage command shows the aging fields in readable form:
The hash field has the format $id$salt$hash. The id tells you the algorithm. Common values are 6 for SHA-512 crypt, y for yescrypt (the default on recent Debian, Ubuntu and Fedora releases), and 5 for SHA-256. The salt makes identical passwords produce different hashes.
Special values in this field are not hashes:
! or !! at the start means the password is locked, so password login fails;* means the account has no valid password and can never log in with one, which is typical for system accounts;Do not use a normal editor on these files while other tools may change them at the same time. A typo can lock every user out, including root. Use the dedicated tools instead:
useradd, usermod, userdel and passwd update both files consistently.sudo vipw for /etc/passwd and sudo vipw -s for /etc/shadow. They lock the file during editing.sudo pwck afterwards to verify that every line is well formed and that every entry in one file has a partner in the other.Groups follow the same split. /etc/group lists group names, GIDs and members, and /etc/gshadow holds group passwords and administrators. On systems using systemd-homed or centralised directories, some accounts are not in these files at all, which is another reason to use getent.
/etc/passwd readable by everyone?Programs need it to map UIDs to names and to find home directories and shells. It contains no secrets now that hashes live in /etc/shadow.
/etc/shadow is !?Not with a password. The account is locked for password login, but SSH keys can still work on many setups unless you also expire the account or set the shell to nologin.
x in /etc/passwd mean?It tells the system that the password hash is stored in /etc/shadow. If you see a hash there instead, shadow passwords are not in use for that account.
Run awk -F: '$3 == 0 {print $1}' /etc/passwd. Only root should appear, and any extra name is a serious security warning.
/etc/passwd is a world-readable list of accounts with seven fields: name, password placeholder, UID, GID, comment, home and shell. /etc/shadow stores password hashes and aging data in nine fields and is readable by root only. Use getent, chage, vipw and pwck instead of raw edits, and treat any extra UID 0 account or empty password field as a problem to fix.