/etc/passwd is the plain-text local user account database of Linux and other Unix-like systems. Each line describes one account in seven colon-separated fields: login name, password placeholder, user identifier, primary group identifier, comment, home directory and login shell.
In Linux permissions, the passwd file is the place where a name such as alice becomes the numeric UID that the kernel actually checks when it evaluates file ownership, process credentials and access rights. It is read by login, sudo, ls, ps and almost every tool that shows a user name, which is why it must remain readable by all users while staying writable only by root.
The seven fields of an /etc/passwd entry
Every entry follows the format name:password:UID:GID:GECOS:home:shell, and a missing colon corrupts the line. A typical entry looks like alice:x:1000:1000:Alice Novak:/home/alice:/bin/bash. The table below explains each field.
| Position | Field | Example | Meaning |
|---|---|---|---|
| 1 | Login name | alice | Unique name used to sign in |
| 2 | Password field | x | Placeholder pointing to /etc/shadow |
| 3 | UID | 1000 | Numeric user identifier checked by the kernel |
| 4 | GID | 1000 | Primary group, resolved through /etc/group |
| 5 | GECOS | Alice Novak | Full name and optional contact data |
| 6 | Home directory | /home/alice | Initial working directory and $HOME |
| 7 | Login shell | /bin/bash | Program started after login |
The kernel itself never reads the file. It only knows numeric UIDs and GIDs; the mapping to names is done in user space by the C library through the Name Service Switch (NSS), configured in /etc/nsswitch.conf. For that reason, getent passwd alice is the correct way to query an account, because it also covers LDAP, SSSD or systemd-userdbd sources that never appear in the local file.
Why passwords moved to /etc/shadow
Early Unix systems stored the password hash directly in the second field. Because every user and many programs must read the file, this exposed hashes to offline cracking by any local account. Modern Linux uses shadow passwords: the second field contains x, and the real hash lives in /etc/shadow, readable only by root and, on some distributions, the shadow group.
| File | Typical mode and owner | Contents |
|---|---|---|
| /etc/passwd | 0644 root:root | Account names, UIDs, homes and shells |
| /etc/shadow | 0640 root:shadow or 0000 root:root | Password hashes and aging rules |
| /etc/group | 0644 root:root | Group names, GIDs and members |
| /etc/gshadow | 0640 root:shadow or 0000 root:root | Group passwords and administrators |
The value of the second field still matters. An x means look up the shadow file, while an empty second field means the account has no password at all on many configurations, a serious weakness. A leading * or ! in the corresponding shadow entry marks an account whose password login is disabled.
UID ranges and special accounts
The UID decides privilege, not the name. Any entry with UID 0 has full root power, regardless of whether it is called root or something else. Distributions reserve ranges through /etc/login.defs, where UID_MIN and SYS_UID_MAX separate human users from service accounts.
| UID range | Account type | Typical login shell |
|---|---|---|
| 0 | Root account | /bin/bash or /bin/sh |
| 1 to 999 | System and service accounts | /usr/sbin/nologin or /bin/false |
| 1000 to 60000 | Regular human users | /bin/bash, /bin/zsh or similar |
| 65534 | The nobody account | /usr/sbin/nologin |
Service accounts such as www-data or sshd exist so that daemons run without root privileges. Their shell is set to a non-interactive program like nologin, which refuses interactive sessions while still allowing the account to own files and processes.
Managing the passwd file safely
Administrators should change accounts through dedicated tools rather than by editing the file directly. Each tool updates /etc/passwd, /etc/shadow and related files consistently and takes the necessary locks.
| Task | Recommended tool | What it does |
|---|---|---|
| Create an account | useradd or adduser | Adds entries and creates the home directory |
| Change shell or home | usermod or chsh | Edits the relevant fields atomically |
| Remove an account | userdel | Deletes entries and optionally the home |
| Edit by hand | vipw | Locks the file and checks it on save |
| Verify consistency | pwck | Reports malformed or duplicate entries |
| Query accounts | getent passwd | Reads all configured NSS sources |
Direct editing with an ordinary text editor risks concurrent writes and syntax errors. Because login depends on parsing this file, a single malformed line can block all logins, including root, until the system is repaired from a rescue environment. vipw prevents this by locking the file and offering to edit the shadow file as well.
Security checks and common mistakes
Because /etc/passwd defines who can log in and with which UID, it is a frequent target for persistence after an intrusion. Routine audits compare the file with a known-good baseline and look for the warning signs below.
- A second account with UID 0, which gives an attacker hidden root access.
- An empty password field that permits login without credentials.
- A writable /etc/passwd, for example mode
0666, which lets any user add accounts. - Service accounts with interactive shells, which widen the attack surface.
- Duplicate UIDs, which make two names share the same file ownership.
A related misconception is that deleting a line removes a user completely. Files on disk keep the numeric owner UID, so they show up as an unnamed number in ls -l, and a new account that later receives the same UID inherits those files. Locating orphaned files with find / -nouser should be part of any account removal procedure.
Explained without jargon
Think of /etc/passwd as the staff list of a computer. Each line names one person or service, gives them an employee number, says which team they belong to, where their desk is and which program greets them after they sign in.
Despite its name, it no longer contains passwords. Those are kept in a separate, locked file. The list itself stays open so that every program can turn numbers into readable names, but only the administrator can change it.
A typical use case
A systems administrator at a university department inherits a research server and runs a quick audit. The command awk -F: '$3 == 0' /etc/passwd lists two lines instead of one: root and an unfamiliar account called backupsvc, also with UID 0.
Further checks show that the account was created by a former contractor and has a valid password hash in /etc/shadow. The administrator locks it with usermod -L, sets its shell to nologin, confirms with pwck that the files are consistent and then removes it with userdel. A find / -nouser scan finds no orphaned files. The result is that only one root-equivalent account remains, and the incident goes into the department security log.