CIS120 Linux Fundamentals by Scott Shaper

Understanding /etc/passwd, /etc/shadow, and /etc/group

Linux stores user and group information in three main text files: /etc/passwd, /etc/shadow, and /etc/group. Think of /etc/passwd as the system's phone book for user accounts—it lists every user, with username, user ID, home directory, and default shell. /etc/shadow is the locked drawer where actual password hashes and expiration data are kept; only root can read it. /etc/group is the list of teams: it defines groups and which users belong to them for permission sharing. You normally don't edit these files by hand—tools like useradd, usermod, and passwd do that—but understanding their format helps you see how accounts are stored and how to look up information with grep, getent, and similar commands.

Quick Reference

File What It Is
/etc/passwd Text file listing all user accounts (one per line); seven colon-separated fields
/etc/shadow Secure file storing password hashes and aging info (root-only read); nine fields
/etc/group Text file listing all groups (one per line); four colon-separated fields

Understanding /etc/passwd

/etc/passwd lists every user who can log in (or run programs) on the system. Each line has exactly seven fields, separated by colons.

When This File Matters

Format of Each Line

A typical line looks like:

jdoe:x:1001:1001:Jane Doe:/home/jdoe:/bin/bash
Field Name Meaning Example
1UsernameLogin namejdoe
2Password placeholderUsually x; real password is in /etc/shadowx
3UIDUser ID (number); 0 = root1001
4GIDPrimary group ID1001
5GECOSExtra info (full name, etc.); often just the full nameJane Doe
6Home directoryUser's home directory path/home/jdoe
7ShellDefault shell (e.g. /bin/bash or /usr/sbin/nologin)/bin/bash

Viewing /etc/passwd

You can read the file with cat, less, or grep. Only root can change it; normal users can usually read it.

View and search

# View the whole file (may be long)
cat /etc/passwd
# or
less /etc/passwd

# Search for one user
grep jdoe /etc/passwd

# List only usernames (first field)
cut -d: -f1 /etc/passwd

Special Accounts

You'll often see accounts with UID 0 (root), low UIDs for system accounts (e.g. daemon, nobody), and /usr/sbin/nologin or /bin/false as the shell—those are for services, not real people logging in.

Understanding /etc/shadow

/etc/shadow holds the actual password hashes and related data. Unlike /etc/passwd, it is readable only by root, so nobody can see or steal the password hashes. Each line corresponds to a user in passwd and has nine colon-separated fields.

When This File Matters

Format of Each Line

A typical line looks like:

jdoe:$6$rounds=...$hashedpassword...:19000:0:99999:7:::
Field Meaning Example
1Username (must match /etc/passwd)jdoe
2Password hash (or !/* for locked/disabled)$6$... or !
3Last password change (days since Jan 1, 1970)19000
4Minimum days between password changes0
5Maximum days until password expires99999
6Days to warn before expiration7
7Account expiration date (days since epoch, or empty)empty
8Reservedempty
9Reservedempty

Viewing /etc/shadow

Only root can read /etc/shadow. Normal users get "Permission denied." Use sudo if your account has permission.

View and search (as root or with sudo)

# View the file (requires root)
sudo cat /etc/shadow

# Search for one user
sudo grep jdoe /etc/shadow

# Check if an account is locked (second field is ! or *)
sudo grep jdoe /etc/shadow

Security note: Don't share shadow output or copy hashes; treat them as secret. Use passwd, chage, or usermod to change passwords or policies instead of editing /etc/shadow by hand.

Understanding /etc/group

/etc/group is the list of teams on the system. Groups let you give permissions to several users at once (e.g. everyone in the "developers" group can read a project directory). Each line defines one group: group name, GID, and which users are members.

When This File Matters

Format of Each Line

Each line has four fields separated by colons:

developers:x:1005:jdoe,jsmith,mkay
Field Meaning Example
1Group namedevelopers
2Password (usually x; group passwords are rarely used)x
3GID (group ID)1005
4List of usernames in the group (comma-separated, no spaces)jdoe,jsmith,mkay

Every user has a primary group (stored in /etc/passwd); that group doesn't have to list the user in /etc/group because membership is implied. The member list in /etc/group is for additional (supplementary) groups.

Viewing /etc/group

Most systems allow any user to read /etc/group. You can use cat, grep, or getent.

View and search

# View the whole file
cat /etc/group
# or
less /etc/group

# Search for one group
grep developers /etc/group

# List only group names (first field)
cut -d: -f1 /etc/group

# See which groups a user is in
groups jdoe
# or
id jdoe

Tips for Success

Common Mistakes to Avoid

Best Practices