Without PAM, every program — login, sshd, sudo — keeps its own hard-coded way of checking passwords, and the only way to change it is to rewrite the code. PAM moves this check into pluggable modules: the administrator assembles a chain of them for each service without touching the applications themselves. The idea came from PAM at Sun Microsystems, and the Linux-PAM project has been carrying it forward for Linux ever since.
How the stack is arranged
An application built against the libpam library calls its functions and gets a pass-or-fail answer, without knowing which modules ran or in what order. The set of modules for each service is described in the files of the /etc/pam.d/ directory (the file name is the service name, for example sshd); the /etc/pam.conf file is the older all-in-one format, where the service name goes in the first column. Each module is a separate .so file in /lib/security or /lib64/security.
A configuration line has five fields: service, task type, control, module, arguments. The task type is one of four groups: auth (establish who it is), account (whether this account is allowed in right now, for example by time of day), password (changing a password), session (actions before and after — mounting a directory, writing to the log). The control field sets what happens to the module’s result; typical values:
| Control | Behaviour |
|---|---|
required | the module must pass; on failure the chain still runs to the end, but the outcome is a denial |
requisite | like required, but on failure the chain stops immediately |
sufficient | on success the chain finishes successfully provided there have been no earlier failures; a failure is ignored |
optional | the result matters only if it is the only module for that task type |
Typical modules
pam_unix— the classic check against/etc/shadow, the “historical” way of signing in;pam_faillock— locks out sign-in after too frequent failed attempts;pam_tally2— an older counter of failed sign-ins, superseded by pam_faillock;pam_nologin— denies sign-in to everyone except root while the/etc/nologinfile exists;pam_wheel— only lets members of the wheel group use su;pam_mkhomedir— creates the home directory on first sign-in;pam_tty_audit— turns on logging of terminal input for auditing.
Example: protection against password guessing
# /etc/pam.d/sshd (fragment)auth required pam_faillock.so preauth deny=5 fail_interval=900 unlock_time=600auth sufficient pam_unix.soauth [default=die] pam_faillock.so authfail deny=5 fail_interval=900 unlock_time=600account required pam_faillock.soThe same pam_faillock is also configured through the /etc/security/faillock.conf file, which the module itself treats as the preferred way: deny, fail_interval and unlock_time are set there. Editing the /etc/pam.d/ files is part of the basic set of Linux hardening measures, alongside configuring SSH and sudo.
Sources
the term is written from these pages- Linux-PAM System Administrators' Guidegithub.com/linux-pam/linux-pam/blob/master/doc/sag/Linux-PAM_SAG.xml(opens in a new tab)
- pam.conf(5) — синтаксис конфигурацииgithub.com/linux-pam/linux-pam/blob/master/doc/man/pam.conf-syntax.xml(opens in a new tab)
- faillock.conf(5) — настройки pam_faillockgithub.com/linux-pam/linux-pam/blob/master/modules/pam_faillock/faillock.conf.5.xml(opens in a new tab)
Verified 9 Nov