Kahibaro
Discord Login Register

User information files

Overview

On a typical Linux system, basic information about users and groups is stored in a small set of text files under /etc. These “user information files” are read by tools like login, su, sudo, and id, and by low‑level system libraries (e.g. getpwnam(3)).

In modern systems, these files often coexist with other sources (LDAP, Active Directory, etc.) through the Name Service Switch (/etc/nsswitch.conf), but understanding the local files is essential for administration, recovery, and troubleshooting.

In this chapter you’ll focus on:

Details on creating users, managing passwords, and groups are handled in other chapters; here the focus is on the files themselves.


`/etc/passwd`: Basic User Database

Historically, /etc/passwd contained all user information, including hashed passwords. For security, modern systems store passwords in /etc/shadow instead, but /etc/passwd still holds core account data.

View it with:

cat /etc/passwd

Each line represents one account, with fields separated by colons (:):

username:x:UID:GID:gecos:home:shell

Example line:

alice:x:1000:1000:Alice Example,,,:/home/alice:/bin/bash

Field breakdown:

  1. Username
    • Login name (e.g. alice, root, www-data).
    • Must be unique on the system.
  2. Password placeholder
    • Typically x on modern systems, meaning “password is stored in /etc/shadow”.
    • Sometimes ! or * to indicate no login via password, depending on setup.
    • If you ever see an actual hashed password here, the system is using an old/unsafe configuration.
  3. UID (User ID)
    • Numeric identifier for the user (e.g. 0, 1000, 1001).
    • 0 is always root.
    • Normal user accounts generally start at some distribution‑specific value (commonly 1000).
    • System/service accounts typically use low UIDs (e.g. < 1000 or < 500).
  4. GID (Primary Group ID)
    • Numeric ID of the user’s primary group.
    • The name for this GID is looked up in /etc/group (or other sources).
  5. GECOS (Comment / User Info)
    • Free‑form informational field, often containing:
      • Full name
      • Office number
      • Phone numbers
    • Fields are sometimes comma‑separated, e.g. Alice Example,Room 42,555-0100,
    • Used by commands like finger or getent passwd.
  6. Home directory
    • Path to the user’s home directory (e.g. /home/alice, /root).
    • Used as the default directory on login.
  7. Login shell
    • Path to the user’s default shell (e.g. /bin/bash, /bin/zsh, /usr/sbin/nologin).
    • A non‑interactive shell like /usr/sbin/nologin or /bin/false effectively disables interactive logins for that account.

Security and integrity notes for `/etc/passwd`

`/etc/shadow`: Secure Password and Aging Data

/etc/shadow holds password hashes and password aging information. It is designed to be only readable by root and specific system processes, to protect password hashes from normal users.

Viewable only with root privileges:

sudo cat /etc/shadow

Each line corresponds to a user in /etc/passwd:

username:password_hash:last_change:min:max:warn:inactive:expire:reserved

Example:

alice:$y$j9T$8m...$...:19500:0:99999:7:::

Field breakdown:

  1. Username
    • Must match an entry in /etc/passwd.
  2. Password hash / flags
    • Typically contains a hashed password with an identifier of the algorithm, e.g.:
      • $y$... (yescrypt)
      • $6$... (SHA-512)
      • $5$... (SHA-256)
      • $1$... (MD5 – legacy, discouraged)
    • Special values:
      • ! or * as the entire field: account cannot be used for password login.
      • ! prepended to a valid hash (e.g. !$6$...): password locked (cannot be used), but hash preserved.
      • Empty field: password is empty (login without password) – very insecure and generally a misconfiguration.
  3. Last password change (days since epoch)
    • Days since 1 January 1970 (Unix epoch) when the password was last changed.
    • Example: 19500 means “19500 days after 1 Jan 1970”.
    • 0 often means the user must change the password at next login.
  4. Minimum days between changes
    • Minimum number of days before a user is allowed to change their password again.
    • 0 means no minimum; user can change the password at any time.
  5. Maximum days password is valid
    • Number of days after which the password expires and must be changed.
    • Typical default: 99999 (effectively “never expires” in practice).
    • A smaller value enforces regular password rotation.
  6. Warning period
    • Number of days before password expiry that the user will start receiving warnings on login.
    • Example: 7 means warnings begin 7 days before expiry.
  7. Inactive period after expiry
    • Number of days after password expiry that the account remains usable (with forced change) before becoming fully disabled.
    • Empty field or -1 often means “no automatic disable after expiry”.
  8. Account expiration date (days since epoch)
    • Days since 1 Jan 1970 when the account itself expires (not just the password).
    • After this date, the user cannot log in at all.
    • Empty means “no account expiry”.
  9. Reserved / unused
    • Currently not used on many systems; kept for future expansion.

Security characteristics of `/etc/shadow`

`/etc/group`: Group Definitions

/etc/group is similar in structure to /etc/passwd, but for groups. It maps group names to GIDs and lists supplementary group members.

View it with:

cat /etc/group

Each line has this format:

group_name:password_placeholder:GID:member_list

Example:

wheel:x:10:alice,bob

Field breakdown:

  1. Group name
    • Human‑readable name (e.g. users, wheel, docker).
  2. Password placeholder
    • Typically x or *.
    • Historically used for “group passwords”; in modern systems it’s almost never used, and actual group passwords (if any) are in /etc/gshadow.
  3. GID (Group ID)
    • Numeric identifier for this group.
    • Must be unique across groups.
    • Mapped from numeric to name by tools like ls, id, etc.
  4. Member list
    • Comma‑separated list of supplementary members of this group, e.g. alice,bob,charlie.
    • The user’s primary group membership is defined by the GID in /etc/passwd, not here.
    • This list is used for additional memberships that give extra permissions (e.g. access to docker, sudo, audio).

Notes on `/etc/group` usage

`/etc/gshadow`: Secure Group Information

/etc/gshadow is to groups what /etc/shadow is to users. It stores group passwords (rare in practice), administrators, and members in a more secure form.

Viewable with root privileges:

sudo cat /etc/gshadow

Each line has the format:

group_name:password_hash:administrators:members

Example:

wheel:!::alice,bob

Field breakdown:

  1. Group name
    • Must match a group in /etc/group.
  2. Password hash / flags
    • If group passwords are enabled, this would contain their hashed value.
    • Common values:
      • ! or *: group password is disabled.
      • Empty: usually means no group password is set.
    • Group passwords allow users to temporarily join a group by running newgrp, but this is uncommon and generally discouraged for security and manageability reasons.
  3. Administrators
    • Comma‑separated list of group administrators.
    • Admins can manage the group (e.g. add/remove members) via gpasswd.
  4. Members
    • Comma‑separated list of group members.
    • Overlaps conceptually with /etc/group’s member_list field; they should stay in sync.

Synchronization and management

Interactions Between the Files

These four files work together:

Typical flows:

Name Service Switch (/etc/nsswitch.conf) controls whether these files are the only source of information, or whether they are combined with external sources (e.g. files ldap sss).


Best Practices and Safety

Understanding these user information files gives you the foundation needed to diagnose account problems, recover from misconfiguration, and safely manage users and groups at the file level.

Views: 25

Comments

Please login to add a comment.

Don't have an account? Register now!