Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

What Do the Files /etc/passwd and /etc/shadow Contain?

Linux
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedDec 4, 2026
5 min read

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.

Table of Contents

  • Why Linux keeps accounts in two files
  • The seven fields of /etc/passwd
    • Reading the file with standard tools
  • The nine fields of /etc/shadow
    • What the hash field means
  • Editing the files safely
  • Related files
  • Frequently Asked Questions
    • Why is /etc/passwd readable by everyone?
    • Can I log in if the password field in /etc/shadow is !?
    • What does the x in /etc/passwd mean?
    • How do I find users with UID 0?
  • Summary
  • Related Articles

Why Linux keeps accounts in two files

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:

bash
text

On some distributions /etc/shadow is mode 0000 or 0640, but ordinary users never have read access.

The seven fields of /etc/passwd

Each line has seven fields separated by colons:

text
PositionExampleMeaning
1aliceLogin name
2xPassword placeholder; the real hash is in /etc/shadow
31000User ID (UID)
41000Primary group ID (GID)
5Alice Smith,,,GECOS field: full name and optional contact details
6/home/aliceHome directory
7/bin/bashLogin 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.

Reading the file with standard tools

You can inspect the file with ordinary text tools:

bash
text

To list only accounts that can log in with a real shell:

bash

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:

bash

The nine fields of /etc/shadow

Each line in /etc/shadow has nine colon-separated fields:

text
PositionMeaning
1Login name, matching /etc/passwd
2Password hash, or a locked or disabled marker
3Date of last password change, in days since 1 January 1970
4Minimum days between changes (0 means no minimum)
5Maximum days a password stays valid (99999 means effectively never)
6Days of warning before the password expires
7Days after expiry before the account is disabled
8Account expiry date, in days since 1 January 1970
9Reserved, normally empty

The chage command shows the aging fields in readable form:

bash

What the hash field means

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;
  • an empty field means no password is required, which is dangerous and should be fixed.

Editing the files safely

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:

  1. useradd, usermod, userdel and passwd update both files consistently.
  2. For manual edits, use sudo vipw for /etc/passwd and sudo vipw -s for /etc/shadow. They lock the file during editing.
  3. Run sudo pwck afterwards to verify that every line is well formed and that every entry in one file has a partner in the other.
  4. Keep a root shell open in a second terminal while you test a change, so a mistake does not lock you out.

Related files

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.

Frequently Asked Questions

Why is /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.

Can I log in if the password field in /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.

What does the 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.

How do I find users with UID 0?

Run awk -F: '$3 == 0 {print $1}' /etc/passwd. Only root should appear, and any extra name is a serious security warning.

Summary

/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.

Related Articles

  • How Do You Check the Current User with whoami, id and who?
  • How Do You Add and Delete Users with useradd and userdel?
  • Learn Linux: Complete Study Roadmap from Beginner to Advanced
Share

Similar posts

  • How Do You Read Linux File Permissions like rwxr-xr-x?
  • How Do You Modify Existing Users with the usermod Command?
  • How Do You Create and Manage Groups in Linux?
  • How Do You Change a User Password with the passwd Command?
  • How Do You Add and Delete Users with useradd and userdel?
  • How Do You Check the Current User with whoami, id and who?
  • How Do You Translate and Delete Characters with the tr Command?
  • How Do You Save and Display Output at Once with tee?