CHAPTER 02 30 MIN READ INTERMEDIATE

Users, Authentication & Privilege: passwd, shadow, PAM & sudo

Every Linux investigation eventually comes down to one question: who could act as whom. This chapter covers how accounts, authentication, and privilege actually work under the hood, the account database, the PAM framework behind logins, and how sudo, su, and group membership decide what a user is allowed to become.

user accounts PAM sudo privilege escalation

User Account Structure

Every local account on a Linux system is recorded as one line in /etc/passwd, the account database that the system and most tools consult first. Each line is a set of colon-separated fields, and reading them correctly is the starting point for any account review.

FieldMeaning
UsernameThe login name tied to this account
Password placeholderAn x, meaning the real password hash lives in /etc/shadow, not here
UIDNumeric user ID that the kernel actually uses to enforce permissions
GIDNumeric ID of the account's primary group
Comment / GECOS fieldFree-text field, usually a full name or description
Home directoryWhere the account lands on login and stores its personal files
Login shellThe program started on login, for example a shell, or /usr/sbin/nologin for service accounts that should never get an interactive session

The password hash itself, along with the aging rules around it, lives in a separate file for a reason.

/etc/shadow FieldPurpose
UsernameMatches the corresponding entry in /etc/passwd
Password hashThe actual hashed credential, never stored in the world-readable /etc/passwd
Last change dateWhen the password was last set
Minimum ageDays that must pass before the password can be changed again
Maximum ageDays after which the password expires and must be changed
Warning periodDays before expiry that the user starts getting warned

/etc/passwd is readable by any user, which is why it never holds the real hash. /etc/shadow is restricted instead: RedHat-family systems typically leave it readable by root alone, while Debian-family systems own it root:shadow with group-read, so only root and the shadow group can read it. Either way the credential material stays out of reach of ordinary unprivileged accounts.

UID 0 is root, no matter the name: the kernel grants full root privileges to UID 0, regardless of what the username field says. A second account with UID 0 sitting alongside the standard root entry is not a normal configuration, it is one of the classic backdoor indicators worth checking /etc/passwd for directly.

PAM: Pluggable Authentication Modules

PAM is the framework that most Linux authentication actually runs through: console login, sudo, SSH, and many other services all call into it instead of implementing their own authentication logic. It is stackable, a single login can chain several checks together, and it is configurable per service.

Each service that uses PAM has its own configuration file under /etc/pam.d/, for example one for login, one for sudo, one for sshd. Each file defines which modules run, in what order, and whether a failure there is fatal to the whole authentication attempt.

  • auth: verifies the user is who they claim to be, typically a password check
  • account: checks account restrictions, such as expiry or time-of-day limits
  • password: handles updating credentials
  • session: sets up or tears down things needed for the session, such as mounting a home directory
Why PAM integrity matters to an investigator: because PAM sits directly in the authentication path for nearly every login method on the system, a modified or backdoored PAM module is a known, serious persistence and credential-theft technique. An attacker with root can patch a PAM module to silently accept a hardcoded password or log every credential that passes through it. That is exactly why PAM configuration and module integrity deserve attention during an investigation, not just the account database.

sudo, su, and Privilege Escalation Basics

su switches you to another user's full session, and by default that means authenticating with the target account's own password. sudo instead runs a single command as another user, typically authenticated with your own password, and is governed by rules defined in /etc/sudoers that specify exactly which users can run which commands as which accounts.

That rule-based model is precise when configured well, but a single overly broad rule can hand a low-privilege user a direct path to root. Privilege escalation on Linux tends to fall into a small set of recurring categories.

VectorWhat It Looks Like
Misconfigured sudo ruleA user is allowed to run a command as root that, by design or oversight, gives them a path to a full root shell
SUID binary abuseAn unexpected or unfamiliar setuid binary, the kind of artifact covered in chapter 1, running with elevated privileges it shouldn't need
Writable cron job or scriptA script or job run by a privileged account that a lower-privileged user can modify, a persistence angle chapter 4 covers further
Unpatched kernel vulnerabilityA known local privilege escalation flaw in an outdated kernel version

Privileged Group Membership

Group membership can grant privilege just as directly as a sudoers rule can, and it is easy to overlook during a quick account review.

GroupWhy It Matters
rootFull system privileges, membership here is equivalent to being root
sudo or wheelDepending on the distribution, membership in one of these grants the ability to use sudo
dockerEffectively root-equivalent, since the Docker daemon runs as root and a container can be used to reach and modify the host filesystem

None of these groups look dangerous by name alone, which is exactly why an account-and-group audit is a standard early step in any Linux investigation. A quiet addition to docker or sudo can be just as significant as a new UID 0 account.

Auditing Accounts and Privilege

Pulling the threads from this chapter together, a practical account and privilege review follows a short, repeatable sequence.

1
Enumerate All Accounts and UIDs
Walk through /etc/passwd for every account, its UID, and its shell.
2
Check for Duplicate UID 0 Accounts
Any username besides root carrying UID 0 is a strong backdoor indicator.
3
Review Sudoers Rules
Look for overly broad or unexpected entries in /etc/sudoers.
4
Check Privileged Group Membership
Review who belongs to sudo, wheel, and docker.
5
Look for Unfamiliar SUID Binaries
Flag setuid binaries that are unexpected or don't belong to the base install.

This same checklist feeds directly into chapter 4's persistence hunting, since attackers who gain elevated privilege here almost always try to make it stick somewhere else on the system.

Key Takeaways

  • /etc/passwd is the world-readable account database, while /etc/shadow holds the actual password hash and aging fields, restricted to root (and the shadow group on Debian-family systems).
  • UID 0 means root privileges regardless of username, so a second UID 0 account is a real backdoor indicator to check for directly.
  • PAM is the stackable, per-service framework behind most Linux authentication, configured through files under /etc/pam.d/.
  • A backdoored PAM module sits in the authentication path for nearly everything, making PAM integrity a serious persistence and credential-theft concern.
  • su switches to a full session using the target account's password, while sudo runs a single command using your own password under rules in /etc/sudoers.
  • Privilege escalation commonly comes from misconfigured sudo rules, SUID binary abuse, writable privileged cron jobs, unpatched kernel flaws, or privileged group membership like sudo, wheel, or docker.

Knowledge Check

Click an answer to reveal the explanation.

You find a second account in /etc/passwd, alongside root, that also has UID 0. What does this indicate?

Correct answer: B. The kernel grants root privileges based on UID 0, not the username field, so any second account carrying UID 0 has full root privileges and should be treated as a serious backdoor indicator.

What is PAM, in the context of Linux authentication?

Correct answer: B. PAM is the pluggable, per-service authentication framework configured under /etc/pam.d/ that most Linux authentication paths, including login, sudo, and SSH, are built on.

Why does membership in the docker group matter during a privilege audit?

Correct answer: C. Because the Docker daemon runs as root, membership in the docker group lets a user run a container that can be used to access and modify the host filesystem, making it effectively root-equivalent.