/etc/passwd

Also known as: passwd file

On this page 7

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

PositionFieldExampleMeaning
1Login namealiceUnique name used to sign in
2Password fieldxPlaceholder pointing to /etc/shadow
3UID1000Numeric user identifier checked by the kernel
4GID1000Primary group, resolved through /etc/group
5GECOSAlice NovakFull name and optional contact data
6Home directory/home/aliceInitial working directory and $HOME
7Login shell/bin/bashProgram started after login
Fields of an /etc/passwd line

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.

FileTypical mode and ownerContents
/etc/passwd0644 root:rootAccount names, UIDs, homes and shells
/etc/shadow0640 root:shadow or 0000 root:rootPassword hashes and aging rules
/etc/group0644 root:rootGroup names, GIDs and members
/etc/gshadow0640 root:shadow or 0000 root:rootGroup passwords and administrators
Account files and their typical permissions

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 rangeAccount typeTypical login shell
0Root account/bin/bash or /bin/sh
1 to 999System and service accounts/usr/sbin/nologin or /bin/false
1000 to 60000Regular human users/bin/bash, /bin/zsh or similar
65534The nobody account/usr/sbin/nologin
Common UID ranges on current Linux distributions

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.

TaskRecommended toolWhat it does
Create an accountuseradd or adduserAdds entries and creates the home directory
Change shell or homeusermod or chshEdits the relevant fields atomically
Remove an accountuserdelDeletes entries and optionally the home
Edit by handvipwLocks the file and checks it on save
Verify consistencypwckReports malformed or duplicate entries
Query accountsgetent passwdReads all configured NSS sources
Tools that read or modify account data

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.