The Pluggable Authentication Modules (PAM) library is a generalized API for authentication related services which allows a system administrator to dynamically configure authentication schemes for all PAM-enabled system utilities and applications by adding and removing PAM modules on the running system. It's a layer between Linux applications and native underlying authentication system. PAM is implemented as shared objects or so-files, and the applications communicate with the PAM library through the PAM API.
Traditionally, login authentication is done by comparing the encrypted password for the user in the password file (/etc/shadow), but each program that requires authentication implements its own authentication mechanisms. For example, various services like FTP, SSH, et cetera have individual ways of authenticating their users. As a result, the administrator has to spend unnecessary amount of time in maintaining the database. A PAM service module provides authentication and other security services to such applications.
Syntax for application's configuration files in /etc/pam.d is,
module-type control-flag module-path module-arguments
The four types of PAM services (Management Groups):
The most commonly used control flags :
Fig. 1 : PAM Framework |
Fig. 2 : PAM File System Layout |
Syntax for application's configuration files in /etc/pam.d is,
module-type control-flag module-path module-arguments
The four types of PAM services (Management Groups):
- Authentication Management (auth)
For authenticating users and provide user's information to the application. - Account Management (account)
For verifying the properties of the user's account. - Session Management (session)
For performing any tasks required at initialization and termination of a session. - Password Management (password)
For providing mechanism for managing the properties of a password and also change the authentication requirements for the user.
The most commonly used control flags :
- required
The return code for a required module is stored. In case of first failure, the error message is stored, and parsing is carried out for the rest of the stack. However, the request isn't successful (regardless of response of other modules). - sufficient
The modules after a successful response of this module aren't called. In case of a failed response, other modules are checked. - optional
A failed response doesn't affect the execution of the stack. - requisite
In case of failure, PAM returns to the calling application and reports it instantly. No further rules are checked. - include
The authentication is redirected to another file, rules of which are checked for success. - binding
If the module is successful and no preceding modules that are flagged as required have failed, then remaining modules are skipped. In case of a failure, record the return code and continue processing the stack.
Fig. 3 : Snippet from /etc/pam.d/sshd |
Examples:
1. Setting Password Requirements:
In this example, we set password requirement on a system to require a minimum of one symbol, one digit and a length of 12 characters.
Edit the existing pam_cracklib.so line in /etc/pam.d/system-auth and /etc/pam.d/password-auth so that it reads :
Edit the existing pam_cracklib.so line in /etc/pam.d/system-auth and /etc/pam.d/password-auth so that it reads :
2. Apply Limits to User:
In this example, we set a limit over how many processes an user can create on the machine. Edit /etc/security/limits.conf and add the given lines. It limits the user student to create no more than 5 processes on the system. And, visitor may only have 3 simultaneous open sessions to the machine.
3. Locking Accounts with Failed Logins:
Here, we disable user accounts for 5 minutes in case of 5 sequential failed login attempts. Edit the existing pam_cracklib.so line in /etc/pam.d/system-auth and /etc/pam.d/password-auth so that it reads :
References:
- "Pluggable Authentication Modules" by Kenneth Geisshirt
- Red Hat Customer Portal
- "Pluggable Authentication Modules" by Dag-Erling Smorgrav
Got PAM in 5 minutes. Great job.
ReplyDelete