Understanding the Unix /etc/passwd File
Learn how /etc/passwd stores Unix account identity data, understand all seven fields, use safe administration tools, and troubleshoot account and UID problems.
/etc/passwd is the traditional local account database on Unix-like systems. It maps human-readable user names to numeric user identifiers and records attributes such as a primary group, home directory, and login shell.
This file is usually readable by every local user. Programs need to translate numeric owners shown by the kernel into names, and many utilities must discover account attributes without granting access to password hashes. Readability does not mean the file should be writable by ordinary users.
What /etc/passwd Does—and Does Not—Do
The operating system uses a UID, or user identifier, as a numeric identity. File ownership, process ownership, and many permission checks use the UID rather than the name typed at a prompt. An entry in /etc/passwd associates that UID with a user name and other account attributes.
The file is primarily identity and login-attribute data, not a complete authentication database. Historically, password hashes were stored in its second field. Modern systems normally place a marker such as x in that field and store password hashes and password-aging information in the protected /etc/shadow file.
In other words, identity data answers “Which account is UID 1001?” Credential data answers “Can this authentication attempt prove control of the account?” Keeping those roles separate lets ordinary software read account names without exposing password hashes.
Line Structure
Each non-comment line normally represents one account. The fields are separated by colons, producing this seven-field layout:
name:password-marker:UID:primary-GID:GECOS:home-directory:login-shellField values must not contain an unescaped colon because the colon is the delimiter. A blank line or a line beginning with a comment marker may be ignored by some tools, but handling can vary. Do not experiment by editing the file with an ordinary text editor; use account-management utilities, or use vipw when an exceptional direct edit is unavoidable.
The Seven Fields of /etc/passwd
Example: A Regular User
alex:x:1001:1001:Alex Example:/home/alex:/bin/bashalexis the unique account name.xindicates that password verification data is normally elsewhere, such as /etc/shadow.1001is both the UID and, in this example, the primary GID value.Alex Exampleis descriptive GECOS data./home/alexis the home directory./bin/bashis the interactive login shell.
Common Password-Field Markers
Password locking is not the same as deleting an account. Locking or expiring access preserves the UID and ownership relationship, which is often important for investigation, service continuity, and file recovery.
Account Classes and UID Conventions
UID allocation ranges are conventions, not universal constants. Check local documentation and policy before assigning an identifier. The special UID and GID value 65534 is commonly associated with an unprivileged “ nobody ” or “ nobody-like ” identity when an operation cannot use the original identity, but its name and exact behavior vary by platform. Never infer privileges solely from a familiar number without checking the system.
Related Account Files and NSS
Use cat /etc/passwd to inspect local records, but use getent passwd to query the effective passwd database through NSS:
cat /etc/passwd
getent passwd
getent passwd alex
getent passwd 1001
id alexThe numeric lookup form is supported on many systems, but behavior depends on the NSS implementation. id also reports the effective UID, primary GID, and supplementary groups.
Safe Account Administration
Prefer supported tools because they coordinate related files, apply validation, preserve locking behavior, and perform distribution-specific setup.
# Create a local account; syntax and defaults vary
sudo useradd -m -s /bin/bash alex
# Some distributions provide an interactive alternative
sudo adduser alex
# Set or change a password
sudo passwd alex
# Modify selected attributes
sudo usermod -s /bin/bash alex
# Inspect or change aging and expiry settings
sudo chage -l alex
# Remove a local account only after reviewing ownership and retention policy
sudo userdel alexBefore changes, make an approved backup of relevant account data, record the current effective lookup, and confirm that you have a recovery path. If direct editing is truly necessary, vipw is preferred because it uses locking, validation, and safer editor handling. Related workflows may use a corresponding group-file editor where available.
Changing a UID or primary GID does not automatically make every existing file and service reference correct. Files may retain the old numeric owner, access-control rules may mention the old number, and a service may expect a particular group. Plan ownership migration, update references, and test before changing active production accounts.
Security and Integrity
- The local account database should be owned by an administrative user and writable only by trusted system mechanisms. Exact modes differ by platform, but ordinary users must not be able to modify it.
- Malformed lines, missing fields, duplicate names, invalid numeric values, and inconsistent shadow records can prevent tools or logins from working correctly.
- Duplicate UID 0 entries require immediate investigation. A second name with UID 0 is privileged even if it looks like a normal user.
- An unexpected interactive shell on a service account can expand attack surface. An unsafe or nonexistent shell can also cause legitimate logins to fail.
- Lock or expire an account when access must stop but ownership and records should be preserved. Delete only after retention, evidence, and file-ownership requirements are addressed.
For auditing, compare effective entries from getent passwd with an approved inventory, review every UID 0 account, look for duplicate UIDs and names, inspect shells and home directories, and review recent account-management logs. Include directory-service identities in the audit; checking only the local file is incomplete.
Reading and Troubleshooting Entries
Unknown Numeric File Owner
If a listing shows a number instead of a name, the system could not resolve that UID at the time of display.
getent passwd 1500
cat /etc/nsswitch.confPossible causes include no record for the UID, an unavailable LDAP or SSSD service, an NSS source omitted from configuration, or an account deleted while its files remained. Decide whether ownership should be reassigned or retained for audit and recovery purposes; do not change it merely to make a name appear.
User Cannot Log In
- Query the effective record with
getent passwd username, rather than assuming the local file is authoritative. - Check password and account state with supported tools such as
passwdandchage. - Verify that the shell exists and is permitted for the login method. A noninteractive shell intentionally blocks interactive access.
- Check that the home directory exists and that its ownership and permissions permit the session to start.
- Compare local and directory-service results, then review logs appropriate to SSH, a console login, or another authentication service.
Service Fails After a UID or GID Change
Search for files still owned by the old numeric identity and inspect service configuration and access-control rules for references to the old UID or GID. Confirm that the new primary group supplies the permissions the service expects. Avoid changing identifiers on active accounts unless the migration is planned and tested.
Inconsistent passwd and shadow Data
An interrupted edit, incorrect delimiter count, invalid field, or missing corresponding shadow record can produce warnings or authentication failures. Run:
sudo pwckReview every warning before acting. Under controlled maintenance conditions, use vipw and restore from a known-good backup when appropriate. Do not use an ordinary editor workflow that can bypass locking or leave related account files out of sync.
Unexpected Administrative Account
Audit all entries with UID 0 and compare them with the approved inventory. Investigate unexpected local accounts, privilege mappings from directory services, recent changes, and relevant logs. Disable unauthorized access according to incident-response procedures while preserving evidence.
Safe Account-Administration Workflow
- Confirm the requested change, affected account, identity source, and rollback plan.
- Back up relevant account data and record the current output of
getentandid. - Use
useradd,adduser,usermod,userdel,passwd, orchageas appropriate. - Use
vipwonly for an exceptional direct edit, with maintenance controls and validation. - Verify the effective NSS entry, UID, primary GID, supplementary groups, shell, home directory, and password or expiry state.
- Check file ownership, service access, and login behavior.
- Document the change and audit for unexpected privileged entries or identity anomalies.
Exam-Relevant Notes
- /etc/passwd has seven colon-separated fields.
- The UID is the kernel-facing user identity and controls file ownership association.
- The fourth field is the primary GID, not the complete list of group memberships.
- The GECOS field is descriptive account data, not authentication data.
- Modern systems normally use
xin the passwd password field and protect the hash in /etc/shadow. getenttests the effective NSS view;cat /etc/passwdshows only the local file.- UID 0 is privileged regardless of the account name.
vipwis safer than an ordinary editor for necessary direct passwd-file changes.- Changing a UID or GID can leave existing files and service configuration referencing the old number.
For a related reference, see /etc/passwd.