Bookmarks

PAM — Linux-PAM authentication modules

Pluggable Authentication Modules

The Linux-PAM mechanism that separates user authentication from the program itself: the application merely calls the PAM library, and how exactly to verify the user is up to the administrator.

Also: Linux-PAM, PAM modules

checked 9 Nov

All terms

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:

ControlBehaviour
requiredthe module must pass; on failure the chain still runs to the end, but the outcome is a denial
requisitelike required, but on failure the chain stops immediately
sufficienton success the chain finishes successfully provided there have been no earlier failures; a failure is ignored
optionalthe 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/nologin file 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

bashpam_faillock sits on both sides of the main pam_unix check: preauth keeps a locked-out user out, authfail records the failure, and the account line resets the counter after a successful sign-in
# /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.so

The 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

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

In depth in the references

where the topic is covered in detail