PAM (Pluggable Authentication Modules) handles SSH authentication, and when it fails, you see errors like:
$ ssh user@server
Permission denied, please try again.Or in server logs:
pam_unix(sshd:auth): authentication failure
pam_unix(sshd:account): account username has expired
fatal: Access denied for user username by PAM account configurationPAM issues can block valid users from accessing SSH.
Understand PAM SSH Authentication
SSH uses PAM when UsePAM yes is enabled in sshd_config. PAM handles:
- Password verification
- Account validity checks
- Session setup
- Resource limits
Any PAM module failure blocks SSH access.
Check SSH PAM Configuration
Verify SSH uses PAM:
sudo grep UsePAM /etc/ssh/sshd_configShould show:
UsePAM yesIf set to no, PAM authentication is disabled. Enable it:
sudo sed -i 's/^UsePAM.*/UsePAM yes/' /etc/ssh/sshd_config
sudo systemctl restart sshdExamine PAM SSH Configuration
Check PAM rules for SSH:
cat /etc/pam.d/sshdTypical configuration:
auth required pam_sepermit.so
auth substack password-auth
auth include postlogin
account required pam_nologin.so
account include password-auth
password include password-auth
session required pam_selinux.so close
session required pam_loginuid.so
session create pam_selinux.so open
session required pam_namespace.so
session optional pam_keyinit.so force revoke
session include password-auth
session include postloginCheck Account Status
PAM may reject users due to account issues:
sudo passwd -S usernameOutput:
username PS 2026-01-01 0 99999 7 -1 (Password set, SHA512 crypt.)Check for locked accounts:
sudo passwd -S username | grep LUnlock account:
sudo passwd -u usernameCheck account expiration:
sudo chage -l usernameOutput:
Last password change : Apr 03, 2026
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7Extend expiration:
sudo chage -E -1 username
sudo chage -M 90 usernameCheck Password Lockout
Accounts can be locked after failed attempts:
sudo faillock --user usernameUnlock:
sudo faillock --user username --resetOr using pam_tally2:
sudo pam_tally2 --user username --resetDebug PAM Authentication
Add debug to PAM modules:
# Edit /etc/pam.d/sshd
auth required pam_unix.so debugOr run SSHD in debug mode:
sudo /usr/sbin/sshd -d -p 2222Connect to debug port:
ssh -p 2222 user@serverWatch output for PAM messages.
Check Access Control
PAM access module restricts users:
grep pam_access /etc/pam.d/sshdIf enabled, check rules:
cat /etc/security/access.confRules format:
+ : @group : ALL
- : ALL : ALL EXCEPT LOCALAdd your user:
echo "+ : username : ALL" | sudo tee -a /etc/security/access.confCheck Time Restrictions
PAM time module restricts access hours:
grep pam_time /etc/pam.d/sshdCheck time rules:
cat /etc/security/time.confFormat:
sshd;*;username;MoTuWeThFr0800-1700This allows SSH only during business hours.
Check Login Defs
System-wide login settings:
cat /etc/login.defs | grep -i uidCheck UID limits that PAM might enforce.
Verify Password Hash
Check password hash is valid:
sudo grep username /etc/shadowHash should look like:
username:$6$salt$hash:18000:0:99999:7:::Empty or invalid hash causes PAM failure.
Reset password:
sudo passwd usernameCheck SELinux Contexts
SELinux can block PAM:
sudo ausearch -m avc -ts recent | grep pamRestore contexts:
sudo restorecon -R /etc/pam.d
sudo restorecon -R /etc/securityCheck nologin File
PAM checks /etc/nologin:
cat /etc/nologinIf this file exists, non-root users can't login. Remove it:
sudo rm /etc/nologinCheck SSH AllowUsers
SSH might restrict users before PAM:
sudo grep AllowUsers /etc/ssh/sshd_configIf set, your user must be listed:
AllowUsers admin operator usernameAdd user:
sudo sed -i 's/^AllowUsers.*/AllowUsers admin operator username/' /etc/ssh/sshd_config
sudo systemctl restart sshdMonitor PAM Logs
Watch authentication logs:
sudo tail -f /var/log/auth.log | grep pamOr:
sudo journalctl -u sshd -f | grep pamTest Authentication
Test PAM authentication directly:
# Test with specific user
sudo pamtester sshd username authenticateThis tests PAM without SSH.
Resolution Checklist
- 1.Verify UsePAM is enabled
- 2.Check account status:
passwd -S username - 3.Check account expiration:
chage -l username - 4.Reset password lockout:
faillock --reset - 5.Debug PAM: add
debugoption to modules - 6.Check access.conf rules
- 7.Check time.conf restrictions
- 8.Remove
/etc/nologinif exists - 9.Check AllowUsers in sshd_config
- 10.Watch logs:
journalctl -u sshd -f
PAM authentication failures are usually account status issues or policy restrictions. Start by checking the account status, then examine PAM configuration files for restrictive modules.