Understanding Linux PAM Configuration in /etc/pam.d/
Pluggable Authentication Modules (PAM) provide a flexible, modular
architecture for managing user authentication across the Linux operating
system. The files located in the /etc/pam.d/ directory act
as the control center for this system, defining the exact authentication
policies and security checks enforced for individual applications and
services such as SSH, sudo, and local logins. This article explains the
role of these configuration files, breaks down their syntax and
functional types, and highlights their impact on system administration
and security.
The Role of /etc/pam.d/
Traditionally, authentication logic was hardcoded directly into application software, requiring recompilation whenever policies changed. PAM decouples authentication from applications, allowing administrators to configure rules globally or per service.
The /etc/pam.d/ directory contains service-specific
configuration files. When an application initiates an authentication
request, it queries PAM using its own service name. PAM then reads the
corresponding file in /etc/pam.d/ (such as
/etc/pam.d/sshd for the OpenSSH daemon or
/etc/pam.d/sudo for the sudo utility) to determine which
security checks must be performed. If a specific service file does not
exist, PAM falls back to /etc/pam.d/other.
Configuration Syntax
Each file in /etc/pam.d/ consists of a stack of rules.
Each rule is defined on a single line using a standardized four-column
format:
<module_interface> <control_flag> <module_name> [module_arguments]
1. Module Interfaces (Management Groups)
The first column specifies the scope of the rule:
- auth: Authenticates the user (typically by validating credentials like passwords or MFA tokens) and establishes user credentials such as group memberships.
- account: Verifies that the account is valid, checking conditions such as account expiration, password validity dates, or access-time restrictions.
- password: Handles updating authentication credentials, including enforcing password strength, history checks, and encryption algorithms.
- session: Manages tasks required before user access
is granted and after it terminates, such as mounting user directories,
logging to system logs, or setting resource limits
(
pam_limits.so).
2. Control Flags
The second column determines how PAM responds to the success or failure of a specific module:
- required: The module must succeed for the overall authentication to pass. However, PAM continues evaluating subsequent modules before returning a failure to prevent attackers from discovering which check failed.
- requisite: The module must succeed. If it fails, PAM terminates execution immediately and rejects the request.
- sufficient: If this module succeeds and no previous
requiredmodule has failed, PAM immediately grants access without processing further modules in that stack. - optional: The module's result is generally ignored unless it is the only module defined in the stack.
- include / substack: References shared, system-wide
configuration files (such as
common-authorsystem-auth) to avoid duplicating rules across multiple service files.
3. Module Name and Arguments
The third and fourth columns define the compiled shared library
(located typically in /lib/security/ or
/lib64/security/) and any optional parameters passed to it.
Examples include pam_unix.so for standard Linux password
checks, pam_deny.so to automatically block requests, or
pam_tally2.so / pam_faillock.so for account
lockout policies.
System Impact and Security
The configuration files in /etc/pam.d/ are fundamental
to Linux hardening. Through these files, administrators can implement
Multi-Factor Authentication (MFA), integrate external identity providers
like LDAP or Kerberos, restrict root access to specific terminals, and
establish password complexity rules without modifying application source
code.
Because changes take effect immediately without requiring a daemon
restart, modifications to /etc/pam.d/ carry significant
risk. A misconfigured module or invalid control flag can inadvertently
grant root access to unauthorized users or lock administrative accounts
out of the system entirely.