Skip to content

Linux Foundations / Manage a Linux host ยท Step 3 of 50

Lesson: /etc/passwdSwitch
โ† Linux Foundations

System administration

/etc/passwd

Read the seven fields of /etc/passwd, the local list of user accounts.

/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/bash

Fields are separated by colons:

  1. login name
  2. password field
  3. UID
  4. primary group GID
  5. comment, often the full name (called GECOS)
  6. home directory
  7. 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/passwd

Many 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/nologin

Service 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
root

Changing 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 -c

The 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.