What does one line look like?
deploy:x:1001:1001:Deploy user,,,:/home/deploy:/bin/bash
| # | Field | In the example |
|---|---|---|
| 1 | Login name | deploy |
| 2 | Password placeholder | x, meaning the hash is in /etc/shadow |
| 3 | UID | 1001 |
| 4 | Primary GID | 1001 |
| 5 | GECOS comment | full name and optional contact fields |
| 6 | Home folder | /home/deploy |
| 7 | Login shell | /bin/bash |
Why can everyone read /etc/passwd?
Programs need to turn user IDs into names: ls -l, ps and many others do it constantly as normal users. So the file is world readable, with permissions 644. That was a problem when password hashes lived there, which is why the second field became a plain x and the hashes moved to /etc/shadow, readable only by root and the shadow group. Check both permissions with:
stat -c '%a %U:%G %n' /etc/passwd /etc/shadow /etc/group /etc/gshadow
Expect 644 root:root for passwd and group, and 640 root:shadow on Debian or 0 root:root on the RHEL family for shadow and gshadow.
What is in /etc/shadow?
deploy:$y$j9T$Fq3...$Q0x...:20425:0:99999:7:::
Fields are: name, hash, last change in days since 1970, minimum and maximum age, warning period, inactive period, expiry date and a reserved field. The hash prefix tells you the algorithm: $y$ is yescrypt, the default on current Debian and Ubuntu; $6$ is SHA-512, the default on the RHEL 9 family. A ! or * at the start means the password is locked or was never set. Read aging details with sudo chage -l deploy.
How are UIDs split between system and human accounts?
- UID 0 is root. Any account with UID 0 is root, whatever its name, so there should be exactly one.
- 1 to 999 are system accounts for daemons such as
www-data,postgresorsshd. - 1000 and up are regular users, as set by
UID_MINin/etc/login.defs. - 65534 is
nobody, used for unprivileged tasks and NFS mapping.
awk -F: '$3==0 {print "uid 0:", $1}' /etc/passwd
If that line prints anything other than root, treat it as a possible intrusion and investigate.
How do I read the file in useful ways?
getent passwd deploy
awk -F: '{print $7}' /etc/passwd | sort | uniq -c | sort -rn
column -t -s: /etc/passwd | less -S
The second line counts how many accounts use each shell, a quick way to spot interactive accounts. column lines the fields up for reading. List users in Linux has more ways to filter human accounts.
Should I edit /etc/passwd by hand?
Use the tools whenever you can: useradd, usermod, userdel, chsh and chfn keep passwd, shadow and group consistent and take locks so two edits cannot clash. If you must edit the file directly, use vipw, which locks it and opens your editor, and vipw -s for shadow:
sudo EDITOR=nano vipw sudo pwck -r sudo grpck -r
pwck -r checks the files read only: duplicate names, missing homes, bad shells and lines that do not match shadow. Run it after any manual change. A broken passwd file can lock everyone out, including you over SSH.
What about /etc/group?
sudo:x:27:alice,deploy
Name, password placeholder, GID and a comma separated member list. Primary group membership is set in passwd field 4 and does not appear in this list, which explains why a user's own group often looks empty. Change memberships with usermod command or Add a user to a group.
What does a nologin shell mean?
A shell of /usr/sbin/nologin prints a short refusal and exits. Service accounts use it so they can own files and run processes without allowing anyone to log in as them. If you add a shell to /etc/shells, users can pick it with chsh; leave nologin out of that list.
How do I keep these files safe?
Back them up along with the rest of /etc; a nightly copy with Back up data with rsync is enough. Watch for changes with a simple checksum in cron or a file integrity tool such as AIDE, so a new UID 0 account or an unexpected shell never goes unnoticed.
Is it the same on FreeBSD?
Close, with one difference: FreeBSD keeps the full record, including the hash, in /etc/master.passwd, and generates the public /etc/passwd and binary databases from it. Edit it only with vipw or pw, which rebuild those files.
Machines Where You Hold Full Root
| Server | Processor | Cores / threads | Memory | Storage | Network | Per month | Smallest order |
|---|---|---|---|---|---|---|---|
| E1 | Intel Xeon E3-1240 v3 | 4 / 8 | 16 GB DDR3 | 2x 240 GB SSD | 2x 1 Gbps | $30.52 | $91.56 (3 months) |
| S2 | Intel Xeon E-2356G | 6 / 12 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $58.39 | $58.39 (1 month) |
| S3 | Intel Xeon E-2356G | 6 / 12 | 64 GB DDR4 | 2x 1 TB NVMe | 2x 10 Gbps | $80.38 | $80.38 (1 month) |
Keep Reading
List users in Linux
List every account on a Linux server, tell real users from system accounts, see who is logged in now and who has sudo rights.
Openusermod command
Change an existing Linux account with usermod: add groups without losing old ones, rename, move home folders, lock, expire and change shells.
Openchpasswd command
Set passwords for one or many Linux accounts from a script with chpasswd, choose the hash, avoid leaking secrets and force a change at next login.
OpenLinux file permissions
Read ls -l output, understand owner, group and other bits, umask defaults, ACLs and why root and SELinux sit on top of it all.
OpenFAQ
Quick Answers
The password hash is stored in /etc/shadow, not in this file.
Yes. It holds no secrets, only names, IDs, homes and shells.
Use usermod and related tools, or vipw, which locks the file. Check with pwck -r afterwards.
Look at the prefix in /etc/shadow: $y$ is yescrypt, $6$ is SHA-512.
Technically yes, but the system treats them as the same user. Avoid it.