/etc/passwd is a plain text file listing the local accounts, one per line. Despite its name, on modern systems it does not normally hold passwords.
The seven fields
$ grep '^maya:' /etc/passwd
maya:x:1000:1000:Maya Rao:/home/maya:/bin/bashFields are separated by colons:
- login name
- password field
- UID
- primary group GID
- comment, often the full name (called GECOS)
- home directory
- login shell
An x in the second field means the password hash is kept in /etc/shadow.
Why everyone can read it
$ ls -l /etc/passwd
-rw-r--r-- 1 root root 1448 Mar 9 09:00 /etc/passwdMany programs need to turn UIDs into names, for example ls -l. So the file is world readable, and only root can write it. That is also why the hashes were moved elsewhere.
Service accounts and shells
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinService accounts often use /usr/sbin/nologin or /bin/false as the shell, which stops interactive logins. The path of nologin differs on some systems, such as /sbin/nologin.
Any account with UID 0 has root's power, whatever its name. Check for unexpected ones:
$ awk -F: '$3 == 0 {print $1}' /etc/passwd
rootChanging it
Do not edit the file with a casual text editor. Use useradd, usermod and userdel. If you really must edit by hand, sudo vipw locks the file to prevent two edits at once.
Accounts from LDAP or similar services do not appear in this file. getent passwd shows them too, if the system is configured for it and the service allows listing.
Try it
$ cut -d: -f1,3,7 /etc/passwd
$ getent passwd "$USER"
$ awk -F: '{print $7}' /etc/passwd | sort | uniq -cThe first command prints name, UID and shell. The last counts how many accounts use each shell. Which accounts could actually log in?
Check your understanding
/etc/passwd
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.