Understanding the Unix /etc/passwd File
Learn how /etc/passwd stores local account records, including usernames, UIDs, groups, shells, security markers, administration tools, and troubleshooting methods.
The /etc/passwd file is the traditional local account database on Unix-like operating systems. It maps account names to numeric user IDs and records attributes such as a primary group, home directory, and login shell.
Despite its name, modern systems normally do not store usable password hashes in this file. With shadow passwords enabled, password data and password-aging information are kept in the protected /etc/shadow file, while /etc/passwd remains readable account metadata.
Purpose and Access
Programs need to translate between names and numeric identities. For example, a file may be owned by UID 1001, while a user-facing command displays the corresponding name. Login programs, shells, file tools, and applications also need to discover an account's home directory and login shell.
The standard local file is /etc/passwd. It is normally readable by all users because ordinary applications need to perform identity lookups. Reading the file is different from changing it: modifying account records requires administrative privileges and can affect login, file ownership, services, and running processes.
cat /etc/passwd
The command above displays the local file. On a production system, use a pager or a targeted lookup when possible. Never overwrite the file with shell redirection or edit it casually.
Record Structure
Each non-comment line normally represents one account. Fields are separated by colons, and the conventional layout contains seven fields:
| Position | Field name | Example value | Purpose | Common considerations |
|---|---|---|---|---|
| 1 | Username | alice | Local account name used for login and identity lookup | Normally unique; naming rules vary by system |
| 2 | Password placeholder | x | Indicates password data is handled separately on shadow-password systems | Historical hashes may appear on older or specially configured systems |
| 3 | UID | 1001 | Numeric user identity used for ownership and permission decisions | UID 0 is the superuser identity |
| 4 | Primary GID | 1001 | Numeric identifier of the account's primary group | Group details are resolved through /etc/group or another NSS source |
| 5 | GECOS/comment | Alice Example,, , | Descriptive account information | Conventions and subfields differ between systems |
| 6 | Home directory | /home/alice | Intended working directory for the account | It should exist and have suitable ownership and permissions |
| 7 | Login shell | /bin/bash | Program started for an interactive login session | Service accounts often use a non-login shell |
A fictional ordinary-user record illustrates the layout:
alice:x:1001:1001:Alice Example,,,:/home/alice:/bin/bash
Empty fields can have special meanings, but they can also indicate an incomplete configuration. Missing fields, extra separators, invalid numeric values, or malformed lines can cause account lookup and login problems.
Understanding Each Field
Username
The username is the local account name used in commands, login prompts, ownership displays, and identity lookups. Names should be unique within the identity source and should follow the naming rules expected by the operating system and applications. Some systems restrict characters, length, or whether a name may begin with a digit.
A human account such as alice is intended for an interactive user. A service or system account is intended for a daemon or operating-system component and may never be used by a person directly.
Password Field and Shadow Passwords
Historically, the second field contained an encrypted password hash. Keeping hashes in a world-readable file made offline password attacks easier, so modern Unix-like systems commonly use the shadow password suite. In that arrangement, the second field in /etc/passwd is often x, and the protected hash is stored in /etc/shadow.
| Value or pattern | Typical meaning | Security implication | Notes |
|---|---|---|---|
x | Password data is stored in /etc/shadow | Normal shadow-password arrangement | Exact behavior depends on the account tools and PAM configuration |
A value beginning with ! or another lock marker | Password authentication is commonly locked or disabled | Review the complete password state before changing it | Markers and semantics vary by implementation |
* or an invalid hash marker | Password-based login is commonly prevented | Does not necessarily disable every authentication method | SSH keys, certificates, PAM rules, or other methods may still matter |
| Empty field | May permit password authentication or indicate a dangerous configuration | Requires immediate authorized review | Do not assume its meaning without checking the system's authentication configuration |
Password hashes must not be manually exposed, copied, or placed in logs. Use passwd and the system's account-management tools to change password state.
UID and Identity
A UID, or user identifier, is the numeric identity used by the kernel for file ownership and permission decisions. Names are convenient labels; the kernel primarily evaluates numeric IDs.
UID 0 conventionally identifies root, the privileged superuser identity. Any account record with UID 0 has root-level identity in contexts that accept that account, even if its username is not root. Unexpected UID 0 records require urgent authorized investigation.
Distribution-specific ranges are common but not universal. Regular users often receive higher UIDs, while system accounts frequently receive lower or reserved UIDs. Multiple usernames can technically map to one UID, but this is usually confusing and risky because all such names represent the same kernel identity.
Primary GID
The GID field identifies the account's primary group, meaning the default group associated with the account. The numeric GID is resolved through local or network group databases.
getent group groupname
id alice
Supplementary groups are additional memberships and are normally recorded through group databases such as /etc/group, not as a list in the passwd record. The id command shows the effective UID, primary GID, and supplementary groups.
GECOS or Comment Field
The GECOS field stores descriptive information rather than access-control data. A common convention uses comma-separated subfields for full name, office location, work phone, and home phone. For example, a field might begin with a person's full name and leave later subfields empty.
These conventions differ between operating systems and organizations. Applications should not assume that every comma-separated position is present, accurate, or used for security decisions.
Home Directory
The home-directory field specifies the account's intended home directory, such as /home/alice. Login sessions, shells, and applications commonly use it as the starting working directory and as the location for user configuration and data.
The path is metadata; creating an account does not always guarantee that the directory exists. Normal use requires the directory to exist, be accessible, and have appropriate ownership and permissions. A wrong path or inaccessible parent directory can cause login sessions and applications to fail.
Login Shell
The login-shell field names the program launched for an account's login session. Common interactive shells include /bin/sh, /bin/bash, and other shells installed on the system.
Service accounts commonly use /usr/sbin/nologin or /bin/false so that an interactive session is not provided. A shell path should point to an appropriate executable. On systems that consult it, /etc/shells lists approved login shells, although SSH, PAM, and other policies may impose additional restrictions.
Account Categories
| Category | Typical UID behavior | Home directory behavior | Login shell behavior | Examples of use |
|---|---|---|---|---|
| Root | UID 0 | Usually a fixed administrative directory | Often interactive, but policy may restrict direct login | System administration |
| Ordinary interactive user | Usually assigned from a regular-user range | Often a directory under /home | Interactive shell such as /bin/bash | Human user sessions |
| System or service account | Often assigned from a system-account range | May have no home, or a service-specific state directory | Often /usr/sbin/nologin or /bin/false | Daemons and operating-system services |
| Disabled account | Any valid UID | May remain present for ownership of files | May use a non-login shell and locked password state | Retained data or temporarily blocked access |
UID ranges, directory conventions, and service-account policies vary by operating system and distribution. Treat these patterns as clues, not as universal rules.
Looking Up Accounts
/etc/passwd is only one possible identity source. Name Service Switch, or NSS, determines where the system looks for passwd and group information. The relevant configuration is in /etc/nsswitch.conf. Depending on the environment, sources may include local files, LDAP, NIS, SSSD-backed directories, or systemd-homed.
Use getent when you want the result from configured NSS sources rather than only the local file:
getent passwd
getent passwd alice
getent passwd 1001
id alice
The numeric lookup is an example; whether every NSS backend supports lookup by UID depends on the configured databases. Compare getent passwd alice with the local file when diagnosing unexpected identity results.
| Source | Information provided | Typical permissions | Relationship to /etc/passwd |
|---|---|---|---|
/etc/passwd | Local names, UIDs, GIDs, comments, homes, and shells | Normally world-readable; administrative modification | Traditional local account database |
/etc/shadow | Password hashes and password-aging state | Restricted to privileged access | Complements passwd records on shadow-password systems |
/etc/group | Group names, GIDs, and supplementary memberships | Normally readable; administrative modification | Resolves primary and supplementary group information |
/etc/nsswitch.conf | Lookup order and identity sources | Normally readable; administrative modification | Determines whether lookups use files, network, or other providers |
| LDAP, NIS, SSSD, or systemd-homed | Environment-dependent centralized or dynamic identity data | Depends on service and configuration | May supplement or replace local records in NSS lookups |
Safe Administration
Do not directly edit /etc/passwd with a general-purpose editor unless there is a well-understood administrative reason. Prefer supported tools because they can coordinate related files, apply platform rules, and preserve expected formats.
| Tool | Primary use | Why it is preferred | Verification step |
|---|---|---|---|
useradd | Create an account | Applies account-creation defaults and related database updates | getent passwd username and id username |
usermod | Modify shell, home, UID, or group-related properties | Uses supported account-management behavior | Recheck with getent, id, and filesystem ownership checks |
userdel | Remove an account | Provides deliberate handling of the account record and optional home data | Confirm service configuration and remaining file ownership |
passwd | Set, change, lock, or manage password state | Updates the protected password database correctly | Review account state with approved administrative commands |
vipw | Edit passwd data when direct adjustment is unavoidable | Provides locking and validation protections against concurrent edits | Run available validation checks and test lookups |
pwck | Check passwd and shadow consistency where available | Detects several structural and cross-file problems | Review its output; consult system documentation before automated repairs |
Before changes on a multiuser system, make a tested backup and follow change-control procedures. Keep /etc/passwd, /etc/shadow, /etc/group, service configuration, and filesystem ownership consistent. Changing a UID or GID does not automatically make every existing file ownership relationship correct; ownership may need deliberate adjustment.
usermod --shell /bin/bash alice
getent passwd alice
id alice
The example changes a shell through an account-management tool and then verifies the result. Choose the desired shell only after checking local policy and the account's purpose.
Security and Auditing
A passwd-file review is one part of an authorized security audit. It is not a substitute for reviewing authentication policy, privilege delegation, remote access, and file ownership.
Investigate, in context:
- Unexpected accounts with UID 0.
- Duplicate UIDs or names that obscure which identity owns files.
- Service accounts with interactive shells when an interactive shell is unnecessary.
- Writable home directories or unsafe permissions on account-owned paths.
- Empty password indicators, unexpected lock markers, or unauthorized changes to shadow data.
- Account records whose homes or shells point to unexpected locations.
Pair the review with /etc/shadow, /etc/group, sudo policy, SSH configuration, PAM policy, identity-service configuration, and filesystem ownership checks. Preserve evidence and authorization boundaries during auditing; do not enumerate or alter accounts on systems without permission.
Reviewing Service Accounts
A read-only review can identify accounts whose shell is not a commonly used non-login shell:
getent passwd | awk -F: '$7 != "/usr/sbin/nologin" && $7 != "/bin/false" {print $1, $3, $6, $7}'
This is only a starting point. Some legitimate service or administrative accounts require an interactive shell, and distributions may use different paths. Confirm the owner, service configuration, access policy, and operational need before making any change.
Troubleshooting
Lookup Results Differ
If a name appears in /etc/passwd but getent cannot find it, or if getent returns unexpected data, NSS may be prioritizing another source, a directory service may be unavailable, caching may be involved, or the local record may be malformed.
- Compare the local record with
getent passwd username. - Review the
passwdentry in/etc/nsswitch.conf. - Check logs and the configured LDAP, NIS, SSSD, or other identity client.
An Account Cannot Log In
An account record alone does not guarantee login access. Check whether the shell exists and is permitted, whether the home directory is present and accessible, and whether password state, SSH, PAM, or directory-service policy blocks access. Authentication and service logs often identify the controlling policy.
Files Show an Unknown Numeric UID
This commonly means the account was deleted, the required identity source is unavailable, or UID assignments differ between systems.
getent passwd 1001
Do not simply assign the UID to a new account. First determine which files, services, and systems depend on the existing numeric ownership.
A Service Fails After an Account Change
Check the service configuration, account UID and GID, home or state directory, shell, group membership, directory ownership, and service logs. A changed UID or GID can leave data owned by the old number. Correct ownership deliberately and use supported account tools for further changes.
Passwd and Shadow Data Are Inconsistent
Manual edits can remove fields, create duplicate names or UIDs, or leave a passwd record without a matching shadow record. Make a backup, use vipw where direct adjustment is necessary, and run validation tools such as pwck when provided by the system. Resolve related passwd, shadow, group, and filesystem inconsistencies together.
Key Points
/etc/passwdis a local account metadata database, not normally the location of password hashes on modern Linux systems.- Each record has seven conventional colon-separated fields: username, password placeholder, UID, GID, GECOS, home directory, and login shell.
- UID 0 represents the superuser identity; numeric IDs control ownership and permissions.
- Primary group information comes from the GID field, while supplementary groups are maintained separately.
- Use
getentfor NSS-aware lookups andidfor effective identity and group membership. - Use
useradd,usermod,userdel,passwd, andvipwrather than unsafe direct editing. - Review passwd data together with shadow, group, NSS, PAM, SSH, sudo, and filesystem ownership controls.