Q: SSH connection is failing even after enabling password authentication on the server. What could be the possible causes, and how would you troubleshoot and resolve the issue?
Troubleshooting checklist when password-based SSH authentication fails to function despite editing /etc/ssh/sshd_config to set PasswordAuthentication yes.
Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Check for Modular Drop-in Configs in /etc/ssh/sshd_config.d/
In modern Linux distributions (Ubuntu 22.04+, RHEL 9+, Amazon Linux 2023), `/etc/ssh/sshd_config` includes drop-in files from `/etc/ssh/sshd_config.d/*.conf`. Cloud providers often drop a `50-cloud-init.conf` file that explicitly sets `PasswordAuthentication no`, which overrides the main file.
# Inspect effective sshd configuration
sshd -T | grep passwordauthentication
grep -rn "PasswordAuthentication" /etc/ssh/sshd_config.d/
Verify Daemon Restart & Syntax Validation
Editing `sshd_config` has no effect until the service is restarted. Validate configuration syntax before restarting to avoid getting locked out.
sshd -t # Validate syntax
systemctl restart sshd || systemctl restart ssh
Verify User Account Password Status & Shadow Lock
On cloud instances (AWS EC2, GCP), default users (`ec2-user`, `ubuntu`) are created with no password or a locked password (`!` or `*` in `/etc/shadow`). Password authentication will reject the login until an actual password is set via `passwd`.
passwd ec2-user
# Verify shadow file status (P = valid password, L = locked, NP = no password)
passwd -S ec2-user
Inspect PAM Authentication & SELinux Contexts
Ensure `UsePAM yes` is enabled in `sshd_config`. Check `/etc/pam.d/sshd` and review system audit logs for SELinux denials.
# Check sshd failure logs in real time
journalctl -u sshd -f
# Look for: "Failed password for invalid user" or "User ec2-user not allowed because account is locked"
- Run sshd -T | grep passwordauthentication to verify the actual evaluated configuration.
- Check /etc/ssh/sshd_config.d/ drop-in directory for cloud-init override files.
- Verify the user account actually has a password set using passwd -S (cloud accounts are locked by default).
- Review journalctl -u sshd logs to see exact PAM or shadow authentication rejection reasons.