/etc/passwd — The File That Defines Every Account on Your System
/etc/passwd is the plain-text database of every user account on a Linux system — one line per account, seven colon-separated fields, world-readable.
What is /etc/passwd, and Why Care?
It’s not a command — it’s a file, and one of the most important on any Linux machine. Every account that can log in, run a service, or own a file has a line here. When you run id, whoami, or ls -l, the names in the output are looked up from this file (and /etc/group).
Each line looks like this:
alice:x:1000:1000:Alice Smith,,/home/alice:/bin/bash
Why Learn /etc/passwd?
- It’s where the identity model becomes concrete — users, groups, home directories, and shells all in one readable file.
- It explains half the output you see —
id,ls -l,ps, and login prompts all pull names from here. - It’s a debugging tool — “does this account exist? what shell? what home?” is a
grepaway. - It’s safe to read — world-readable by design; the passwords are not here (they’re in
/etc/shadow).
Think of
/etc/passwdas the system’s phone book: it maps every account number to a name, a home, and a shell. Reading it is how you stop guessing about who and what is running on your machine.
1. Reading the Seven Fields
Each line has exactly seven colon-separated fields:
alice : x : 1000 : 1000 : Alice Smith,,/home/alice : /bin/bash
1 2 3 4 5 6
Wait — six fields? Count again, splitting field 5 properly:
1. username — the login name
2. password placeholder — always `x` (the real hash lives in /etc/shadow)
3. UID — numeric user ID; 0 is root
4. GID — numeric primary group ID
5. GECOS — comment: full name, office, phone (free text)
6. home directory — where the user lands on login
7. login shell — the program run at login
Example:
$ head -3 /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
- Field 2 being
xis universal on modern systems — it means “password hash is elsewhere”. - Field 7 of
/usr/sbin/nologinmeans the account cannot be logged into interactively — that’s how services are locked down.
2. Finding Accounts
grep is the everyday tool for querying the file:
# Does this account exist?
grep '^bob:' /etc/passwd
# Show all "real" human accounts (UID >= 1000)
awk -F: '$3 >= 1000 {print $1}' /etc/passwd
# Which accounts have a real login shell?
grep -v nologin /etc/passwd | grep -v /bin/sync
Example:
$ grep '^alice:' /etc/passwd
alice:x:1000:1000:Alice Smith,,/home/alice:/bin/bash
$ awk -F: '$3 >= 1000 {print $1, $7}' /etc/passwd
alice /bin/bash
bob /bin/bash
- The
^name:anchor prevents partial matches (e.g.,bobmatchingbobby). - Filtering out
nologinshells is the quick way to list accounts that can actually log in.
3. Who Wrote This Line, and When?
The file is edited by tools, not by hand:
| Tool | What it does to /etc/passwd |
|---|---|
useradd | Adds a new account line |
usermod | Modifies a field (shell, home, etc.) |
userdel | Removes the account line |
passwd | Writes to /etc/shadow, not here |
vipw | Safely edits the file with checks |
Example:
# See what useradd just created
$ sudo useradd -m -s /bin/bash testuser
$ grep testuser /etc/passwd
testuser:x:1004:1004::/home/testuser:/bin/bash
- Direct edits are possible but discouraged — use
vipw, which locks the file and validates syntax. - A corrupted
/etc/passwdcan prevent anyone from logging in, which is why the safe-edit tool exists.
4. The Companion Files
/etc/passwd is one member of a small family:
$ grep alice /etc/group
alice:x:1000:
sudo:x:27:alice,dev
$ sudo grep alice /etc/shadow
alice:$y$j9T$Qz9...:19700:0:99999:7:
| File | Contents | Readable by |
|---|---|---|
/etc/passwd | Accounts: names, UIDs, shells | Everyone |
/etc/shadow | Password hashes + expiry policy | Root only |
/etc/group | Groups and their members | Everyone |
/etc/gshadow | Group passwords (rarely used) | Root only |
- Together these four files are the identity system — everything
idprints comes from them. - The split into shadow exists for security: hashes must not be world-readable, or they could be cracked offline.
5. UID Ranges at a Glance
The numeric ID in field 3 tells a story about the account:
0 → root (full admin)
1–999 → system/service accounts (created with useradd -r)
1000–65533 → regular human users
65534 → nobody (the least-privileged account)
Example:
# Service accounts live in the low range
$ awk -F: '$3 < 1000 && $3 != 0 {print $1, $3}' /etc/passwd | head -5
daemon 1
bin 2
sys 3
sync 4
# The nobody account
$ grep nobody /etc/passwd
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
- When a file is owned by a UID with no matching line (e.g., after deleting a user),
ls -lshows the raw number instead of a name — a classic sign of an orphaned account.
Common Pitfalls
- Looking for passwords here. Field 2 is just
x; the hashes are in/etc/shadow. If you find a real hash in/etc/passwd, the system is misconfigured (or ancient). - Editing the file by hand. Use
vipw(or theuseradd/usermodtools) — a stray character can lock everyone out. - Assuming every line is a person. Most lines are services (
daemon,www-data,postgres) withnologinshells; filter before concluding. - Confusing GECOS with “comment”. Field 5 is structured free text (full name, office, phone) — some tools parse it, so don’t put arbitrary junk there.
- Deleting a user without cleaning files.
userdelwithout-rleaves files owned by a UID that no longer has a line here —ls -lwill show bare numbers. - Trusting names over numbers. Permissions are enforced by UID/GID; if names look right but access fails, compare the numeric IDs with
id.
Related Pages
| Page | Why it’s related |
|---|---|
| useradd | Creates the lines that appear in this file |
| passwd | The password tool whose name points here (historically) |
| id | Prints identity info looked up from this file |
| whoami | The username every line of this file defines |
| su | Switching between accounts defined here |
| ls | ls -l resolves owner names through this file |
/etc/passwd Cheatsheet
| Command | Meaning |
|---|---|
cat /etc/passwd | View every account line |
grep '^alice:' /etc/passwd | Look up one exact account |
awk -F: '{print $1, $3, $7}' /etc/passwd | List usernames, UIDs, and shells |
awk -F: '$3 >= 1000' /etc/passwd | List human (non-system) accounts |
grep -v nologin /etc/passwd | Accounts that can log in interactively |
grep nobody /etc/passwd | The least-privileged account |
sudo vipw | Safely edit the file with validation |
getent passwd alice | Resolve an account (works with LDAP too) |