Static..

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:

PositionField nameExample valuePurposeCommon considerations
1UsernamealiceLocal account name used for login and identity lookupNormally unique; naming rules vary by system
2Password placeholderxIndicates password data is handled separately on shadow-password systemsHistorical hashes may appear on older or specially configured systems
3UID1001Numeric user identity used for ownership and permission decisionsUID 0 is the superuser identity
4Primary GID1001Numeric identifier of the account's primary groupGroup details are resolved through /etc/group or another NSS source
5GECOS/commentAlice Example,, ,Descriptive account informationConventions and subfields differ between systems
6Home directory/home/aliceIntended working directory for the accountIt should exist and have suitable ownership and permissions
7Login shell/bin/bashProgram started for an interactive login sessionService 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 patternTypical meaningSecurity implicationNotes
xPassword data is stored in /etc/shadowNormal shadow-password arrangementExact behavior depends on the account tools and PAM configuration
A value beginning with ! or another lock markerPassword authentication is commonly locked or disabledReview the complete password state before changing itMarkers and semantics vary by implementation
* or an invalid hash markerPassword-based login is commonly preventedDoes not necessarily disable every authentication methodSSH keys, certificates, PAM rules, or other methods may still matter
Empty fieldMay permit password authentication or indicate a dangerous configurationRequires immediate authorized reviewDo 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

CategoryTypical UID behaviorHome directory behaviorLogin shell behaviorExamples of use
RootUID 0Usually a fixed administrative directoryOften interactive, but policy may restrict direct loginSystem administration
Ordinary interactive userUsually assigned from a regular-user rangeOften a directory under /homeInteractive shell such as /bin/bashHuman user sessions
System or service accountOften assigned from a system-account rangeMay have no home, or a service-specific state directoryOften /usr/sbin/nologin or /bin/falseDaemons and operating-system services
Disabled accountAny valid UIDMay remain present for ownership of filesMay use a non-login shell and locked password stateRetained 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.

SourceInformation providedTypical permissionsRelationship to /etc/passwd
/etc/passwdLocal names, UIDs, GIDs, comments, homes, and shellsNormally world-readable; administrative modificationTraditional local account database
/etc/shadowPassword hashes and password-aging stateRestricted to privileged accessComplements passwd records on shadow-password systems
/etc/groupGroup names, GIDs, and supplementary membershipsNormally readable; administrative modificationResolves primary and supplementary group information
/etc/nsswitch.confLookup order and identity sourcesNormally readable; administrative modificationDetermines whether lookups use files, network, or other providers
LDAP, NIS, SSSD, or systemd-homedEnvironment-dependent centralized or dynamic identity dataDepends on service and configurationMay 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.

ToolPrimary useWhy it is preferredVerification step
useraddCreate an accountApplies account-creation defaults and related database updatesgetent passwd username and id username
usermodModify shell, home, UID, or group-related propertiesUses supported account-management behaviorRecheck with getent, id, and filesystem ownership checks
userdelRemove an accountProvides deliberate handling of the account record and optional home dataConfirm service configuration and remaining file ownership
passwdSet, change, lock, or manage password stateUpdates the protected password database correctlyReview account state with approved administrative commands
vipwEdit passwd data when direct adjustment is unavoidableProvides locking and validation protections against concurrent editsRun available validation checks and test lookups
pwckCheck passwd and shadow consistency where availableDetects several structural and cross-file problemsReview 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.

  1. Compare the local record with getent passwd username.
  2. Review the passwd entry in /etc/nsswitch.conf.
  3. 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/passwd is 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 getent for NSS-aware lookups and id for effective identity and group membership.
  • Use useradd, usermod, userdel, passwd, and vipw rather than unsafe direct editing.
  • Review passwd data together with shadow, group, NSS, PAM, SSH, sudo, and filesystem ownership controls.