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.
PasswordAuthentication yes in /etc/ssh/sshd_config, the issue typically stems from configuration overrides in /etc/ssh/sshd_config.d/, un-restarted sshd daemons, cloud-init overwriting settings, locked user accounts, or PAM / SELinux security policy rejections."
Want to master this scenario in a live sandbox? The Linux Foundation's Certified System Administrator (LFCS) & SRE Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: When SSH password authentication fails despite setting PasswordAuthentication yes in /etc/ssh/sshd_config, the issue typically stems from configuration overrides in /etc/ssh/sshd_config.d/, un-restarted sshd daemons, cloud-init overwriting settings, locked user accounts, or PAM / SELinux security policy rejections.
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.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Issuing immediate kill -9 (SIGKILL) commands rather than allowing graceful termination via kill -15 (SIGTERM) when configuring Connection Failing Even SIGKILL immediately halts execution without allowing processes to flush memory buffers, commit database transactions, or remove stale PID locks.
-
Overlooking file system inode exhaustion (df -i) when diagnosing 'No space left on device' errors when configuring Connection Failing Even
Millions of small files or unrotated session tokens can exhaust available file system inodes even when standard disk storage (
df -h) shows ample free space. - Exhausting open file descriptor allocations (ulimit -n) under intensive concurrent socket connections when configuring Connection Failing Even Reaching file descriptor exhaustion throws 'Too many open files' errors, preventing services from accepting new TCP client socket connections.
-
Permitting defunct zombie processes to accumulate without fixing parent process SIGCHLD waitpid reaping when configuring Connection Failing Even
Zombie processes consume process table entries; accumulating zombies can exhaust the system maximum PID limit (
pid_max).