PAM and the login path
How Linux checks a password: PAM's four module types, the stacks in /etc/pam.d, what required, requisite and sufficient do, and what runs before a shell.
PAM and the login path
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Programs like login, sshd, su and sudo do not check passwords themselves. They call PAM, and the files in /etc/pam.d decide which modules run for each service.
- PAM has four module types: auth proves identity, account decides whether this account may log in now, password changes credentials, session sets up and tears down the session.
- Modules are stacked and evaluated in order. required fails the stack but keeps going, requisite fails immediately, sufficient succeeds immediately if nothing earlier failed, optional rarely matters. Bracketed [value=action] syntax can also jump over modules.
- Debian builds its shared stacks (common-auth and friends) with pam-auth-update; Fedora and RHEL generate system-auth with authselect. Hand edits to generated files are overwritten.
- Always keep a root shell open while changing PAM. One wrong line can stop every login, including sudo.
Why not let each program check passwords?
In early Unix, login read /etc/passwd, hashed what you typed, and compared. So did su, ftpd, the screen locker, and every other program that let someone in. Then sites wanted Kerberos, then LDAP, then one-time codes, then fingerprint readers. Each change meant patching and recompiling every one of those programs, and keeping them consistent.
PAM, Pluggable Authentication Modules, moved the decision out of the programs. pam(8) describes it as “a system of libraries that handle the authentication tasks of applications”, giving “privilege granting programs (such as login(1) and su(1))” a stable interface to “defer to”. The program asks PAM “is this user allowed in?” and PAM consults configuration that the administrator controls. Adding two-factor authentication to SSH becomes a configuration change.
Four questions, four module types
PAM splits a login into four kinds of work. A program calls a function for each, and each has its own stack of modules. From pam.d(5):
- auth “establishes that the user is who they claim to be”, usually with a password prompt, and can grant credentials.
- account is “non-authentication based account management”: is this account expired, locked, allowed at this hour, allowed from here?
- password handles “updating the authentication token”, what
passwduses. - session covers things “to be done for the user before/after they can be given service”: logging, limits, environment, mounting a home directory.
The program-side functions, per pam(3), are pam_authenticate, pam_acct_mgmt, pam_chauthtok, pam_open_session and pam_setcred.
Where stacks live
Each PAM-aware program has a service name and a file in /etc/pam.d/ with that name: login, sshd, su, sudo, passwd. Lines read type control module [arguments]. A file named other supplies defaults for services with no file of their own. Most service files pull in shared stacks rather than repeating them.
Here is the Debian 13 /etc/pam.d/login from the official container image, comments removed and lines abbreviated, as I read it on a Mac:
auth optional pam_faildelay.so delay=3000000
auth requisite pam_nologin.so
session required pam_loginuid.so
session required pam_env.so readenv=1
@include common-auth
session required pam_limits.so
@include common-account
@include common-session
@include common-password
pam_nologin refuses non-root logins when /etc/nologin exists. pam_limits applies /etc/security/limits.conf, the subject of the resource limits lesson. pam_env sets environment variables. The real checks are in the included files.
Control flags: how a stack decides
The third field says what a module’s result means. pam.d(5) defines the four classic keywords:
- required: failure “will ultimately lead to the PAM-API returning failure but only after the remaining stacked modules … have been invoked”. The user still sees every prompt, so an attacker cannot tell which check failed.
- requisite: like required, but on failure “control is directly returned to the application”.
- sufficient: if it succeeds “and no prior required module has failed”, PAM returns success “immediately without calling any further modules”. Its failure is ignored.
- optional: matters only “if it is the only module in the stack”.
Each keyword is shorthand for the bracketed syntax, [value=action ...]. The man page gives sufficient as [success=done new_authtok_reqd=done default=ignore]. Actions can also be a number: “jump over the next N modules”.
Now the two families’ actual auth stacks, from the images:
# debian /etc/pam.d/common-auth
auth [success=1 default=ignore] pam_unix.so nullok
auth requisite pam_deny.so
auth required pam_permit.so
# fedora /etc/authselect/system-auth (auth lines)
auth required pam_env.so
auth required pam_faildelay.so delay=2000000
auth sufficient pam_unix.so nullok
auth required pam_deny.so
Trace Debian’s. If pam_unix accepts the password, success=1 jumps over one module, skipping pam_deny, and pam_permit ends the stack in success. If the password is wrong, default=ignore moves on to pam_deny, which always fails, and requisite stops there. Fedora reaches the same result with sufficient and a final required pam_deny. Both end with a module that fails by default, so a misconfigured stack denies rather than allows.
nullok deserves a look. pam_unix(8) says its default is “to not permit the user access to a service if their official password is blank” and that “the nullok argument overrides this default”. Both distributions ship it on. An account with an empty password field can log in at the console without a password.
What happens between the password and the shell
Put together, an SSH password login on a PAM system goes roughly like this:
sshdstarts PAM with the service namesshdand runs the auth stack.pam_unixreads/etc/shadowthrough the smallunix_chkpwdhelper, whichpam_unix(8)describes as checking “the password of the user invoking it”, which is why it is setgidshadowon Debian, as the special bits lesson showed.- The account stack checks expiry and locks set by
chageandusermodin the accounts lesson. - The session stack sets the login UID for auditing, limits, environment and umask, and on systemd systems registers the session with
pam_systemd, which Fedora’s stack loads. - Only then does the program switch to the user’s UID and GIDs and start the shell named in
/etc/passwd.
The ordering is a simplification from the man pages and the stacks above; key-based SSH logins skip the password module but still go through account and session.
Changing PAM safely
On Debian and Ubuntu, common-auth says it “is managed by pam-auth-update by default”. On Fedora and RHEL, system-auth is a symlink into /etc/authselect/ whose header reads “Do not modify this file manually, use authselect instead. Any user changes will be overwritten.” Use those tools. And before touching any PAM file on a remote machine, open a second root session and keep it open until you have tested a fresh login, because a bad auth line can lock out sshd and sudo at once.
About the video
The embed is Safin Singh’s “Linux, Visually: PAM”, June 2023, 29 minutes, in full, on Ubuntu. Chapters cover an introduction to PAM, the configuration files, the line syntax, module control flags, a practical demo and best practices, which follows this lesson’s order closely. It is a small channel. I judged it from the chapters and description, and English from its English auto-caption track, since YouTube reported no original-audio language for it. The lesson adds the Fedora authselect side and traces real stacks line by line. theurbanpenguin’s eleven-minute overview is in deeper.
What was run: reading /etc/pam.d and /etc/authselect files from the downloaded Debian and Fedora images, on a Mac. Semantics are quoted from pam.d(5), pam(8), pam(3) and pam_unix(8) on man7.org, checked 2026-11-28.
Check yourself
In a stack, a required module fails but processing continues to the next module. Why does PAM not stop straight away?
So that the user sees the same prompts and timing whether or not an early check failed, which avoids revealing which part was wrong. The failure is remembered and the stack still returns failure.
What do the two lines 'auth sufficient pam_unix.so' and 'auth required pam_deny.so' achieve together on Fedora?
If the Unix password check succeeds, the stack succeeds at once and pam_deny is never reached. If it fails, evaluation continues to pam_deny, which always fails, so the overall result is failure.
A user's password is correct but login is still refused. Which PAM module type is the likely place to look?
account, which checks things like expiry, locking, access rules and /etc/nologin after authentication has succeeded.
Where should you add a new PAM module on Fedora so it survives updates?
Through authselect, for example by creating a custom profile and selecting it, rather than editing /etc/authselect/system-auth, which authselect regenerates.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.