Each PAM configuration file contains a group of directives that define the module and any controls or arguments with it.
2.2.2.1. PAM Module Interfaces
Four types of PAM module interface are available. Each of these corresponds to a different aspect of the authorization process:
auth
— This module interface authenticates use. For example, it requests and verifies the validity of a password. Modules with this interface can also set credentials, such as group memberships or Kerberos tickets.
account
— This module interface verifies that access is allowed. For example, it may check if a user account has expired or if a user is allowed to log in at a particular time of day.
password
— This module interface is used for changing user passwords.
session
— This module interface configures and manages user sessions. Modules with this interface can also perform additional tasks that are needed to allow access, like mounting a user's home directory and making the user's mailbox available.
An individual module can provide any or all module interfaces. For instance, pam_unix.so
provides all four module interfaces.
In a PAM configuration file, the module interface is the first field defined. For example, a typical line in a configuration may look like this:
auth required pam_unix.so
This instructs PAM to use the pam_unix.so
module's auth
interface.
Module interface directives can be stacked, or placed upon one another, so that multiple modules are used together for one purpose. If a module's control flag uses the sufficient
or requisite
value, then the order in which the modules are listed is important to the authentication process.
Stacking makes it easy for an administrator to require specific conditions to exist before allowing the user to authenticate. For example, the reboot
command normally uses several stacked modules, as seen in its PAM configuration file:
[root@MyServer ~]# cat /etc/pam.d/reboot
#%PAM-1.0
auth sufficient pam_rootok.so
auth required pam_console.so
#auth include system-auth
account required pam_permit.so
The first line is a comment and is not processed.
auth sufficient pam_rootok.so
— This line uses the pam_rootok.so
module to check whether the current user is root, by verifying that their UID is 0. If this test succeeds, no other modules are consulted and the command is executed. If this test fails, the next module is consulted.
auth required pam_console.so
— This line uses the pam_console.so
module to attempt to authenticate the user. If this user is already logged in at the console, pam_console.so
checks whether there is a file in the /etc/security/console.apps/
directory with the same name as the service name (reboot). If such a file exists, authentication succeeds and control is passed to the next module.
#auth include system-auth
— This line is commented and is not processed.
account required pam_permit.so
— This line uses the pam_permit.so
module to allow the root user or anyone logged in at the console to reboot the system.
2.2.2.2. PAM Control Flags
All PAM modules generate a success or failure result when called. Control flags tell PAM what do with the result. Modules can be stacked in a particular order, and the control flags determine how important the success or failure of a particular module is to the overall goal of authenticating the user to the service.
There are several simple flags, which use only a keyword to set the configuration:
required
— The module result must be successful for authentication to continue. If the test fails at this point, the user is not notified until the results of all module tests that reference that interface are complete.
requisite
— The module result must be successful for authentication to continue. However, if a test fails at this point, the user is notified immediately with a message reflecting the first failed required
or requisite
module test.
sufficient
— The module result is ignored if it fails. However, if the result of a module flagged sufficient
is successful and no previous modules flagged required
have failed, then no other results are required and the user is authenticated to the service.
optional
— The module result is ignored. A module flagged as optional
only becomes necessary for successful authentication when no other modules reference the interface.
include
— Unlike the other controls, this does not relate to how the module result is handled. This flag pulls in all lines in the configuration file which match the given parameter and appends them as an argument to the module.
The order in which required
modules are called is not critical. Only the sufficient
and requisite
control flags cause order to become important.
There are many complex control flags that can be set. These are set in attribute=value pairs; a complete list of attributes is available in the pam.d
manpage.
2.2.2.3. PAM Module Names
The module name provides PAM with the name of the pluggable module containing the specified module interface. The directory name is omitted because the application is linked to the appropriate version of libpam
, which can locate the correct version of the module.
2.2.2.4. PAM Module Arguments
PAM uses arguments to pass information to a pluggable module during authentication for some modules.
For example, the pam_userdb.so
module uses information stored in a Berkeley DB file to authenticate the user. Berkeley DB is an open source database system embedded in many applications. The module takes a db
argument so that Berkeley DB knows which database to use for the requested service. For example:
auth required pam_userdb.so db=/path/to/BerkeleyDB_file
Invalid arguments are generally ignored and do not otherwise affect the success or failure of the PAM module. Some modules, however, may fail on invalid arguments. Most modules report errors to the /var/log/secure
file.