Understanding the /etc/shadow File in Linux

The /etc/shadow file is a system file that stores hashed passwords and password aging information for each user account on a Linux system. It works alongside /etc/passwd
, which contains basic user account details but does not store passwords.
Ownership and permissions depend on the distribution. Debian and Ubuntu set the owner
to root, the group to shadow, and the permissions
to 640. Fedora, RHEL, and their derivatives use root for both owner and group, with permissions set to 0000. Either way, regular users cannot read the password hashes, and root reads the file regardless because it bypasses file permission checks. To check your own system, run stat -c '%A %U:%G' /etc/shadow.
This guide explains the /etc/shadow file format, what each field means, and how to query password information safely.
/etc/shadow Format
The /etc/shadow file contains one entry per line, each representing a user account. To view the contents, use cat
with sudo:
sudo cat /etc/shadowThe first line typically describes the root user, followed by system and normal user accounts. New entries are appended at the end of the file.
Each line contains nine colon-separated fields:
mark:$6$.n.:17736:0:99999:7:::
[--] [----] [---] - [---] ----
| | | | | |||+-----------> 9. Unused
| | | | | ||+------------> 8. Expiration date
| | | | | |+-------------> 7. Inactivity period
| | | | | +--------------> 6. Warning period
| | | | +------------------> 5. Maximum password age
| | | +----------------------> 4. Minimum password age
| | +--------------------------> 3. Last password change
| +---------------------------------> 2. Encrypted Password
+----------------------------------------> 1. UsernameField Descriptions
Username: The login name for the user account. This matches the username in
/etc/passwd.Encrypted Password: The hashed password. The format depends on the hashing algorithm and may include cost parameters as well as a salt and hash. Common algorithm prefixes include:
$1$- MD5$2b$- bcrypt$5$- SHA-256$6$- SHA-512$y$- yescrypt (the default on Debian 11+, Ubuntu 22.04+, Fedora 35+, and RHEL 10)
For example, yescrypt uses
$y$parameters$salt$hash. The parameters control the computational and memory cost of hashing.If the password field contains an asterisk (
*) or an exclamation point (!), the user cannot log in using password authentication. Other login methods like key-based authentication or switching to the user withsudo su - usernameare still allowed. New accounts get!until you set a password. System accounts such asdaemonandbinuse*.An exclamation point in front of a hash (
!$y$...) means the password is locked. Thepasswd -landusermod -Lcommands add the!. Thepasswd -ucommand removes it, and the original password works again.On older Red Hat-based releases such as CentOS, you will also see a double exclamation point (
!!) for new accounts and locked passwords. Current releases, including RHEL 10, Debian 13, and Ubuntu 26.04, use a single!.An empty password field means the account has no password at all. The
passwd -dcommand leaves the field in this state. Local users may then be able to switch to the account withsuwithout entering a password, depending on the PAM configuration. Thepam_unix.somodule rejects empty passwords unless itsnullokoption is enabled. SSH rejects empty passwords by default, but you should still set a password or lock password authentication.Last password change: The date when the password was last changed, expressed as the number of days since January 1, 1970 (the Unix epoch). A value of
0forces the user to change the password at the next login. An empty field disables password aging.Minimum password age: The number of days that must pass before the user can change the password again. A value of
0means the password can be changed at any time.Maximum password age: The number of days after which the user must change the password. The default value is
99999(approximately 274 years), which effectively means the password never expires.Warning period: The number of days before the password expires during which the user receives a warning message at login.
Inactivity period: The number of days after the password expires during which the expired password is still accepted and the user must change it at the next login. After this period elapses, the user cannot log in until an administrator resets the password. This field is often empty.
Expiration date: The date when the account is disabled, expressed as days since the Unix epoch. An empty field means the account does not expire.
Unused: Reserved for future use. This field is currently ignored.
Example Entry
The following is an example /etc/shadow entry:
linuxize:$y$j9T$zYHn...$x5rG...:18009:0:120:7:14::This entry contains the following information about the user “linuxize”:
- The password is hashed with yescrypt (
$y$), andj9Tencodes the hashing parameters. The salt and hash are truncated here for readability. - The password was last changed on April 23, 2019 (day 18009 since the epoch).
- There is no minimum password age (
0). - The password must be changed at least every 120 days.
- The user receives a warning message 7 days before the password expires.
- The expired password remains accepted for 14 days, during which the user must change it at login. After that period, the user cannot log in until an administrator resets the password.
- There is no account expiration date.
Viewing Password Information
Do not edit the /etc/shadow file by hand. Always use the appropriate commands to query and modify password information.
To view the password aging information for a specific user, use the chage command with the -l option:
sudo chage -l linuxizeLast password change : Apr 23, 2019
Password expires : Aug 21, 2019
Password inactive : Sep 04, 2019
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 120
Number of days of warning before password expires : 7To look up a single user entry from the shadow database, use getent:
sudo getent shadow linuxizeThe command prints only that user’s line, in the same format as the file.
To change a user password, use the passwd
command:
sudo passwd linuxizeTo modify password aging settings such as the maximum age or warning period, use chage:
sudo chage -M 90 -W 14 linuxizeThis sets the maximum password age to 90 days and the warning period to 14 days.
When a manual edit cannot be avoided, open the file with vipw -s:
sudo vipw -svipw locks the file until you save and close the editor. No other tool can change it during that time.
Quick Reference
| Task | Command |
|---|---|
| View the shadow file | sudo cat /etc/shadow |
| Look up a single user | sudo getent shadow username |
| View password aging info | sudo chage -l username |
| Change a user password | sudo passwd username |
| Set maximum password age | sudo chage -M DAYS username |
| Set warning period | sudo chage -W DAYS username |
| Lock a user password | sudo passwd -l username |
| Unlock a user password | sudo passwd -u username |
| Edit the file safely | sudo vipw -s |
Troubleshooting
Permission denied when reading /etc/shadow
The file is not readable by regular users. On Debian and Ubuntu the shadow group can read it, while on Fedora and RHEL only root can. Use sudo in either case: sudo cat /etc/shadow.
Password field shows ! or *
The account does not have a usable password. An ! or !! means the password is locked or has not been set. A * also prevents password authentication and is common for system accounts. These markers do not by themselves disable other login methods.
chage shows “password must be changed”
The last password change field is set to 0, commonly after chage -d 0 or passwd -e. This forces a password change at the next login. When a password simply exceeds its maximum age, chage -l still displays the expiration date. The user must set a new password at the next login, or an administrator can reset it with sudo passwd username.
Shadow entry missing for a user that exists in /etc/passwd
Run sudo pwconv to synchronize /etc/passwd and /etc/shadow. This creates missing shadow entries.
FAQ
What is the difference between /etc/passwd and /etc/shadow?/etc/passwd contains user account information (username, UID, home directory, shell) and is readable by all users. /etc/shadow stores hashed passwords and password aging data. On Debian and Ubuntu it is readable by root and the shadow group, while Fedora and RHEL restrict it to root.
How do I check which hashing algorithm my system uses?
Check the ENCRYPT_METHOD setting in /etc/login.defs and the pam_unix.so line in /etc/pam.d/common-password (Debian and Ubuntu) or /etc/pam.d/system-auth (Fedora and RHEL). On current Debian, Ubuntu, and RHEL releases, both are set to yescrypt. To see which algorithm hashed an existing password, check its prefix with sudo getent shadow username | cut -d: -f2 | cut -c1-3.
What does a !! password field mean?!! marks an account without a usable password on older Red Hat-based releases. It appears on new accounts before a password is set and on locked passwords. Current releases, including RHEL 10, Debian 13, and Ubuntu 26.04, use a single ! instead.
Can I move passwords back to /etc/passwd?
You should not. Storing passwords in /etc/passwd is insecure because that file is world-readable. The shadow file exists specifically to keep password hashes protected.
How do I force a user to change their password at next login?
Run sudo chage -d 0 username. This sets the last password change date to the epoch, which forces a password change at the next login.
Conclusion
The /etc/shadow file stores hashed passwords and password aging information for every user on a Linux system. Use chage and passwd to manage those values, and see the /etc/passwd file guide
for the account details stored alongside them.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page