2.2. PAM Configuration Files
/etc/pam.d/directory contains the PAM configuration files for each PAM-aware application.
2.2.1. PAM Service Files
/etc/pam.d/directory. Each file in this directory has the same name as the service to which it controls access.
/etc/pam.d/directory. For example, the
loginprogram defines its service name as
loginand installs the
/etc/pam.d/loginPAM configuration file.
2.2.2. PAM Configuration File Format
module_interface control_flag module_name module_arguments
18.104.22.168. PAM Module Interfaces
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 checks 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.
pam_unix.soprovides all four module interfaces.
auth required pam_unix.so
requisitevalue, then the order in which the modules are listed is important to the authentication process.
rebootcommand 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.somodule 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.somodule to attempt to authenticate the user. If this user is already logged in at the console,
pam_console.sochecks 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.somodule to allow the root user or anyone logged in at the console to reboot the system.
22.214.171.124. PAM Control Flags
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
sufficient— The module result is ignored if it fails. However, if the result of a module flagged
sufficientis successful and no previous modules flagged
requiredhave 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
optionalonly 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.
requiredmodules are called is not critical. Only the
requisitecontrol flags cause order to become important.
126.96.36.199. PAM Module Names
libpam, which can locate the correct version of the module.
188.8.131.52. PAM Module Arguments
pam_userdb.somodule 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
dbargument 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
2.2.3. Sample PAM Configuration Files
Example 2.1. Simple PAM Configuration
#%PAM-1.0 auth required pam_securetty.so auth required pam_unix.so nullok auth required pam_nologin.so account required pam_unix.so password required pam_cracklib.so retry=3 password required pam_unix.so shadow nullok use_authtok session required pam_unix.so
- The first line is a comment, indicated by the hash mark (
#) at the beginning of the line.
- Lines two through four stack three modules for login authentication.
auth required pam_securetty.so— This module ensures that if the user is trying to log in as root, the tty on which the user is logging in is listed in the
/etc/securettyfile, if that file exists.If the tty is not listed in the file, any attempt to log in as root fails with a
auth required pam_unix.so nullok— This module prompts the user for a password and then checks the password using the information stored in
/etc/passwdand, if it exists,
pam_unix.somodule to allow a blank password.
auth required pam_nologin.so— This is the final authentication step. It checks whether the
/etc/nologinfile exists. If it exists and the user is not root, authentication fails.
NoteIn this example, all three
authmodules are checked, even if the first
authmodule fails. This prevents the user from knowing at what stage their authentication failed. Such knowledge in the hands of an attacker could allow them to more easily deduce how to crack the system.
account required pam_unix.so— This module performs any necessary account verification. For example, if shadow passwords have been enabled, the account interface of the
pam_unix.somodule checks to see if the account has expired or if the user has not changed the password within the allowed grace period.
password required pam_cracklib.so retry=3— If a password has expired, the password component of the
pam_cracklib.somodule prompts for a new password. It then tests the newly created password to see whether it can easily be determined by a dictionary-based password cracking program.The argument
retry=3specifies that if the test fails the first time, the user has two more chances to create a strong password.
password required pam_unix.so shadow nullok use_authtok— This line specifies that if the program changes the user's password, using the
passwordinterface of the
- The argument
shadowinstructs the module to create shadow passwords when updating a user's password.
- The argument
nullokinstructs the module to allow the user to change their password from a blank password, otherwise a null password is treated as an account lock.
- The final argument on this line,
use_authtok, provides a good example of the importance of order when stacking PAM modules. This argument instructs the module not to prompt the user for a new password. Instead, it accepts any password that was recorded by a previous password module. In this way, all new passwords must pass the
pam_cracklib.sotest for secure passwords before being accepted.
session required pam_unix.so— The final line instructs the session interface of the
pam_unix.somodule to manage the session. This module logs the user name and the service type to
/var/log/secureat the beginning and end of each session. This module can be supplemented by stacking it with other session modules for additional functionality.