Linux Command Reference ยท Special Files and Directories
The /etc/shadow file
Reference for /etc/shadow: the nine fields, how password hashes and locked accounts look, password aging dates, permissions and safe ways to edit it.
/etc/shadow stores the secret part of every local account: the password hash and the password-aging rules. It exists because /etc/passwd must be readable by everyone (programs map user IDs to names with it), while password hashes must not be. The shadow file is readable only by root and, on Debian-based systems, by the shadow group.
Each line describes one account and has nine fields separated by colons. The first field is the login name, matching a line in /etc/passwd. You almost never edit the file by hand; you change it with passwd, chage, useradd and usermod, and you only read it as root.
name:hash:lastchange:min:max:warn:inactive:expire:reserved
Try it
The sandbox user is not root and cannot read the real file, so this example takes apart a made-up line (the hash is fake) and converts the day counts into dates.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
The nine fields, in order:
| Field | Description |
|---|---|
| 1. login name | Must match an entry in /etc/passwd. |
| 2. password | The hash in the form $id$salt$hash, or a special value (see below). |
| 3. last change | Days since 1970-01-01 when the password was last changed. Empty means aging is off; 0 forces a change at next login. |
| 4. minimum | Days that must pass before the user may change the password again. |
| 5. maximum | Days after which the password must be changed. 99999 effectively means never. |
| 6. warning | Days before expiry on which the user is warned. |
| 7. inactive | Days after expiry during which the password can still be changed at login; after that the account is disabled. |
| 8. expire | Day number on which the whole account is disabled. Empty means never. |
| 9. reserved | Unused. |
The hash prefix tells you the algorithm: $1$ MD5 (obsolete), $5$ SHA-256, $6$ SHA-512, $y$ yescrypt (the default on recent Debian, Ubuntu and Fedora). Special values in field 2: * and !! mean no valid password, a leading ! means the account was locked with the real hash kept behind it, and an empty field means no password at all.
Errors / edge cases: a malformed line or a missing trailing newline can make tools refuse to read the file, so edit it only with vipw -s, which locks the file and checks it.
Usage notes
- Permissions: typically
-rw-r----- root shadow(mode 640) or600. A world-readable shadow file lets anyone crack passwords offline. - Locking:
passwd -l userputs!in front of the hash, but it does not stop SSH key login. Useusermod -e 1 useror set a nologin shell to block everything. Seepasswdandusermod. - Aging is per account: use
chage -l userto list it andchage -M 90 userto set the maximum age. - Dates are days, not seconds, counted in UTC. Convert with
date -d "1970-01-01 + N days". - A backup,
/etc/shadow-, is kept by the tools and has the same sensitivity. - Not every login uses it. Accounts from LDAP, SSSD or systemd-homed are stored elsewhere.
- Group passwords live in
/etc/gshadow, not here.