PAM (Pluggable Authentication Modules) — Understanding Linux Authentication¶
PAM (Pluggable Authentication Modules) is the authentication framework used by Linux to control how users are authenticated and authorized. Instead of every application implementing its own authentication mechanism, applications such as SSH, sudo, login, and passwd rely on PAM to provide a centralized, flexible, and secure authentication system.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand PAM
- Learn how Linux authentication works
- Understand PAM modules
- Read PAM configuration files
- Understand PAM control flags
- Configure basic authentication policies
- Integrate enterprise authentication
- Apply PAM security best practices
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 – Text Processing
- Module 4 – File Management and Permissions
- Module 5 Lessons 1–8
Why Learn PAM?¶
Imagine a company with:
- SSH logins
- sudo authentication
- Console logins
- FTP access
- Database authentication
- Multi-Factor Authentication (MFA)
Should every application implement its own password verification?
No.
Linux uses PAM to provide one centralized authentication framework.
What is PAM?¶
PAM stands for:
Pluggable Authentication Modules
PAM provides a common authentication interface between:
Applications simply ask PAM to authenticate users.
PAM decides how authentication should happen.
PAM Authentication Flow¶
User Login
│
▼
Application
(ssh, sudo, login)
│
▼
PAM
│
▼
Authentication Module
│
▼
Password / LDAP / MFA / Kerberos
│
▼
Access Granted or Denied
Why PAM?¶
Benefits:
- Centralized authentication
- Consistent security
- Flexible configuration
- Easy integration
- Enterprise authentication support
Without PAM, every application would require its own authentication implementation.
PAM Configuration Directory¶
Configuration files are stored in:
View:
Example:
Each application has its own PAM configuration.
Example PAM File¶
Display:
Example:
auth required pam_unix.so
account required pam_unix.so
password required pam_unix.so
session required pam_unix.so
Each line defines how authentication is processed.
PAM Components¶
Every PAM rule has four parts:
Example:
Breakdown:
| Part | Meaning |
|---|---|
auth | Authentication step |
required | Control flag |
pam_unix.so | Authentication module |
| (optional) | Module arguments |
PAM Module Types¶
Authentication¶
Verifies identity.
Examples:
- Password verification
- SSH authentication
- MFA
Account¶
Checks account status.
Examples:
- Account expiration
- Login restrictions
- Time-based access
Password¶
Handles password changes.
Examples:
- Password updates
- Complexity rules
- Password history
Session¶
Manages user sessions.
Examples:
- Login
- Logout
- Resource limits
- Session logging
PAM Control Flags¶
required¶
Authentication must succeed.
Failure is remembered, but PAM continues processing the remaining modules.
requisite¶
Authentication must succeed.
Failure immediately stops authentication.
sufficient¶
If successful, authentication succeeds immediately (provided no earlier required module has failed).
optional¶
Used when the module's result is not essential unless no other modules are configured for that type.
Common PAM Modules¶
| Module | Purpose |
|---|---|
pam_unix.so | Local password authentication |
pam_env.so | Load environment variables |
pam_limits.so | Resource limits |
pam_access.so | Access control |
pam_pwquality.so | Password complexity (commonly used on many distributions) |
pam_faillock.so | Account lockout after failed logins (common on RHEL-based systems) |
Note
The available modules vary depending on the Linux distribution.
Password Complexity¶
Many Linux systems use:
to enforce:
- Minimum length
- Uppercase letters
- Lowercase letters
- Numbers
- Special characters
Example configuration:
Account Lockout¶
Some distributions use:
to lock accounts after repeated failed login attempts.
This helps mitigate brute-force attacks.
PAM and sudo¶
Display:
Every time you execute:
PAM authenticates the user according to the configured policy.
PAM and SSH¶
Display:
When a user connects through SSH:
Enterprise Authentication¶
PAM supports:
- LDAP
- Active Directory
- Kerberos
- Multi-Factor Authentication (MFA)
- Smart Cards
- Biometric authentication (where supported)
Applications don't need to change—only the PAM configuration does.
Common Commands¶
View PAM directory.
View SSH configuration.
View sudo configuration.
View login configuration.
Real Production Examples¶
SSH authentication.
sudo authentication.
Password changes.
Production Perspective¶
PAM is used extensively for:
- Linux servers
- Enterprise authentication
- Active Directory integration
- LDAP authentication
- SSH security
- sudo authentication
- Password policies
- Multi-factor authentication (MFA)
Almost every Linux login passes through PAM.
Hands-on Lab¶
Task 1¶
List PAM configuration files.
Task 2¶
View SSH PAM configuration.
Task 3¶
View sudo PAM configuration.
Task 4¶
View login PAM configuration.
Task 5¶
Search for password quality modules.
Task 6¶
Search for account lockout modules.
Task 7¶
Identify authentication modules.
Task 8¶
Identify session modules.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
ls /etc/pam.d | View PAM services | Administration |
cat /etc/pam.d/sshd | SSH authentication | Troubleshooting |
cat /etc/pam.d/sudo | sudo authentication | Security audits |
grep "^auth" | Find authentication rules | Configuration review |
grep "^session" | Find session rules | Session management |
Production Troubleshooting Scenario¶
Scenario
Users suddenly cannot log in through SSH.
Investigation:
The PAM configuration was modified incorrectly.
Solution:
Restore the correct PAM configuration from backup or reinstall the appropriate PAM package according to your distribution.
After restarting the SSH service (if required), authentication works again.
Best Practices¶
- Avoid manually editing PAM configuration unless you understand the authentication flow.
- Always back up PAM configuration files before making changes.
- Test configuration changes in a non-production environment first.
- Use PAM modules provided by your Linux distribution.
- Document custom authentication policies.
Common Mistakes¶
❌ Editing PAM configuration on production systems without testing.
✅ Edit PAM configuration on production systems without testing only when appropriate and with a backup.
❌ Removing required authentication modules.
✅ This can prevent users—including administrators—from logging in.
❌ Assuming PAM configuration is identical across all Linux distributions.
✅ Module names and configuration files may differ.
Interview Questions¶
Beginner¶
- What does PAM stand for?
- Why is PAM used in Linux?
- Where are PAM configuration files stored?
- Which applications commonly use PAM?
Intermediate¶
- Explain the four PAM module types.
- What is the difference between
requiredandrequisite? - How does PAM support password complexity?
- How does PAM integrate with SSH and sudo?
Architect Level¶
- How would you integrate Linux authentication with Active Directory?
- How would you enforce MFA across enterprise Linux servers?
- Why is PAM considered a flexible authentication framework?
Summary¶
In this lesson, you learned:
- What PAM is
- Linux authentication flow
- PAM configuration files
- PAM module types
- Control flags
- Password policies
- Enterprise authentication
- Production best practices
PAM is the foundation of authentication in Linux. It provides a centralized and flexible framework that allows applications such as SSH, sudo, and login to share a common authentication mechanism while supporting enterprise security requirements.
Key Takeaways¶
- PAM stands for Pluggable Authentication Modules.
- PAM centralizes authentication for Linux applications.
- Configuration files are located in
/etc/pam.d/. - PAM supports local passwords, LDAP, Kerberos, MFA, and more.
- Test PAM changes carefully to avoid authentication failures.
- PAM is a critical component of enterprise Linux security.
What's Next?¶
Multi-user Environment in Linux — Managing Multiple Users on a Single System
You'll explore:
- Multiple concurrent users
- User sessions
- Process ownership
- Session management
- Resource sharing
- User isolation
- Monitoring logged-in users
- Enterprise multi-user best practices
By the end of the module, you'll understand how Linux securely supports multiple users working on the same system simultaneously.