Users, groups and the account files

Beginner · 1 min

How Linux identifies users and groups by number, what /etc/passwd, /etc/shadow and /etc/group hold, system versus human accounts, and NSS lookups.

Before thisThe filesystem hierarchy

Learn Linux TV · 9 min · from 23:50

Users, groups and the account files

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Learn Linux TVReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • The kernel knows only numbers. Every process runs with a user ID and group IDs, and every file is owned by a UID and GID. Names are a lookup the C library does for humans.
  • /etc/passwd maps names to UIDs, primary GIDs, home directories and shells, and is world-readable. Password hashes live in /etc/shadow, readable only by root (and the shadow group on Debian), with ageing fields beside them.
  • /etc/group lists groups and their supplementary members. A user's primary group comes from passwd; supplementary groups come from group.
  • UID 0 is root. System accounts for services sit below UID_MIN (1000 by default) and usually have a nologin shell; human accounts start at 1000.
  • The files are only one source. /etc/nsswitch.conf decides where lookups go (files, systemd, sss for LDAP), so use getent passwd, not cat /etc/passwd, to see what the system actually resolves.

Numbers, not names

When the kernel decides whether a process may open a file, it compares numbers: the process’s user ID and group IDs against the file’s owner UID, group GID and permission bits. It has no idea what “alice” or “www-data” means. Names exist for people, and translating between the two is a user-space job done by the C library.

That split explains a whole class of puzzles. Copy a disk to another machine and ls -l suddenly shows 1003 where a name used to be: the number travelled with the file, but the new machine has no account with that number. Two machines that give the same name different UIDs will confuse NFS and backups the same way. Keeping UIDs consistent across a fleet is a real operational concern.

/etc/passwd

The passwd(5) man page describes one line per account with seven colon-separated fields: name:password:UID:GID:GECOS:directory:shell. The file “should have read permission allowed for all users (many utilities, like ls(1) use it to map user IDs to usernames), but write access only for the superuser.”

Here is the real file from the official Debian 13 container image, which I downloaded and unpacked on a Mac:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
...
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
_apt:x:42:65534::/nonexistent:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin

Eighteen accounts, and only root can log in interactively. The rest are system accounts: identities for services, with a home directory that may not exist and the shell /usr/sbin/nologin, which refuses interactive logins. When nginx runs as www-data and is compromised, the attacker gets www-data’s rights, not root’s. UID 0 is root by definition, and 65534 is nobody, the identity for “no particular user”.

Where is the boundary between system and human accounts? /etc/login.defs sets it. In the Debian, Ubuntu and Fedora images, UID_MIN is 1000 and UID_MAX is 60000, so the first human account gets UID 1000. The login.defs(5) man page gives the system range defaults as 101 up to UID_MIN-1, and Fedora’s file sets SYS_UID_MIN 201 and SYS_UID_MAX 999 explicitly. Distributions assign the low static numbers differently: daemon is 1 on Debian and 2 on Fedora.

/etc/shadow

The x in the password field means “look in /etc/shadow”. passwd(5) recounts the history: everyone used to be able to read the hashes, and once hardware could crack them, distributions moved them to a file “readable by the superuser only”. The shadow(5) man page says it “must not be readable by regular users if password security is to be maintained.”

Its nine fields are the name, the hash, the date of the last change “expressed as the number of days since 1970-01-01”, then minimum age, maximum age, warning period, inactivity period, expiry date and a reserved field. The Debian image’s entries look like root:*:20780:99999:7:::. Day 20780 is 23 November 2026, when the image was built. * is not a valid hash, which the man page says means the account “cannot use a UNIX password to log in”. A ! in front of a real hash means the password is locked. A modern hash starts with a method prefix; libxcrypt’s crypt(5) lists $y$ for yescrypt, which Debian and Fedora set as ENCRYPT_METHOD in login.defs.

The distributions protect the file differently, which I read from the image archives’ metadata:

/etc/shadow mode owner:group
Debian 13, Ubuntu 24.04 -rw-r----- (0640) root:shadow (GID 42)
Fedora 45 ---------- (0000) root:root

Debian lets the shadow group read it so that small helpers installed setgid shadow, such as unix_chkpwd, can verify passwords without being root. Fedora makes those helpers setuid root instead. The special permission bits lesson explains both mechanisms.

/etc/group

/etc/group has four fields, name:password:GID:members, for example sudo:x:27:alice,bob. Every user has one primary group, the GID in their passwd line, which new files get by default. Supplementary groups are the ones that list the user in the fourth field. With USERGROUPS_ENAB yes, the default in all three images, each new user also gets a private group of the same name. The id command shows a user’s UID, primary group and supplementary groups together.

NSS: the files are only one source

Programs do not read /etc/passwd directly. They call C library functions like getpwnam(), and the Name Service Switch decides where to look. nsswitch.conf(5) describes the file that sets “the sources from which to obtain name-service information … and in what order”. The two images differ:

debian: passwd:         files
fedora: passwd:     files systemd

On Fedora, nsswitch.conf is a symlink into /etc/authselect/, managed by the authselect tool, and adds systemd. The nss-systemd(8) man page says that module resolves accounts that systemd creates on the fly, for DynamicUser= services, and keeps root and nobody resolvable “even if they are not listed in /etc/passwd”. On machines joined to LDAP or Active Directory, sss appears here too.

So the reliable query is getent passwd alice or getent group sudo. getent(1) “displays entries from databases supported by the Name Service Switch libraries”, which means it sees exactly what ls, sshd and sudo see.

About the video

The embed is Learn Linux TV’s “Linux Crash Course - Managing Users”, July 2021, clipped to its two closing chapters on /etc/passwd and /etc/shadow (about 9 minutes), where Jay LaCroix goes through the fields on a live system. The auto-generated chapter titles spell it “Etsy Password”, which is how YouTube heard “etc passwd”. The earlier part of the same video is the embed for the next lesson. It does not cover NSS, getent, or the distribution differences, which this lesson adds. I judged it from the chapters and description, and English from the original English audio track. His groups video is in deeper.

What was run: reading the passwd, group, shadow, login.defs and nsswitch files and the archive permission metadata from the downloaded Debian, Ubuntu and Fedora images, on a Mac, and converting the shadow day count to a date. Field definitions are quoted from passwd(5), shadow(5), login.defs(5), nsswitch.conf(5), getent(1), nss-systemd(8) and libxcrypt’s crypt(5), checked 2026-11-28.

Check yourself

  1. 01You restore files from a backup onto a new server and ls -l shows numbers instead of owner names. What happened?

    Ownership is stored as numeric UIDs and GIDs. Those numbers have no matching entries on the new server, so there is no name to display. Create the accounts with the same UIDs or chown the files.

  2. 02Why is the password field in /etc/passwd just an x?

    /etc/passwd must be world-readable so tools can map UIDs to names. The hashes were moved to /etc/shadow, which ordinary users cannot read; the x says to look there.

  3. 03A user can log in on a machine joined to LDAP but does not appear in /etc/passwd. How do you confirm the system can resolve them?

    getent passwd <name>. It asks the Name Service Switch, which follows /etc/nsswitch.conf to sources like sss as well as the local files.

  4. 04In /etc/shadow, what does a password field of ! or * mean, and what does a leading ! in front of a hash mean?

    A field that is not a valid hash, such as ! or *, means the account cannot log in with a password at all. A ! in front of a real hash means the password is locked; removing it restores the old password.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark