📖 ~1 min read
Table of contents
Symptom & Impact
Public-key login fails and admins fall back to password or lose access.
Environment & Reproduction
Common after home migration or permission drift.
ssh -vvv user@host
sudo systemctl status ssh
getent passwd user
Root Cause Analysis
Incorrect ownership or strict mode violations for .ssh and authorized_keys.
Quick Triage
Check sshd config and recent auth logs.
sudo sshd -T | grep -Ei 'pubkeyauthentication|authorizedkeysfile|passwordauthentication'
sudo journalctl -u ssh -n 120 --no-pager
sudo tail -n 120 /var/log/auth.log
Step-by-Step Diagnosis
Verify file permissions and key format.
sudo ls -ld /home/user /home/user/.ssh
sudo ls -l /home/user/.ssh/authorized_keys
sudo ssh-keygen -l -f /home/user/.ssh/authorized_keys

Solution – Primary Fix
Set strict permissions and restart sshd.
Still having issues? Our IT Solutions & Services team can diagnose and resolve this for you. Get in touch for a free consultation.
sudo chown -R user:user /home/user/.ssh
sudo chmod 700 /home/user/.ssh
sudo chmod 600 /home/user/.ssh/authorized_keys
sudo systemctl restart ssh

Solution – Alternative Approaches
Temporarily enable password auth from console for emergency access.
sudoedit /etc/ssh/sshd_config
# set PasswordAuthentication yes temporarily
sudo systemctl restart ssh
Verification & Acceptance Criteria
Key login succeeds and logs show pubkey accepted.
ssh -o PreferredAuthentications=publickey user@host true
sudo journalctl -u ssh -n 40 --no-pager
Rollback Plan
Revert sshd_config to previous hardened state after recovery.
sudo cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%s)
sudo systemctl restart ssh
Prevention & Hardening
Audit SSH permissions and disable password auth after validation.
find /home -maxdepth 2 -name .ssh -type d -exec ls -ld {} ;
sudo sshd -T | grep passwordauthentication
Related Errors & Cross-Refs
May coexist with UFW blocks and wrong user shell settings.
Related tutorial: View the step-by-step tutorial for Ubuntu 24.04 LTS.
View all Ubuntu 24.04 LTS tutorials on the Tutorials Hub →
Browse all common problems & solutions on the Tutorials Hub.
References & Further Reading
Ubuntu OpenSSH server hardening and key management docs.
Need Expert Help?
If you cannot resolve this yourself, our team offers hands-on Server Management, Managed IT Services, and flexible Support Plans. Contact us today — we respond within one business day.