Affected versions: Ubuntu 24.04 LTS

📖 ~1 min read

Table of contents
  1. Symptom & Impact
  2. Environment & Reproduction
  3. Root Cause Analysis
  4. Quick Triage
  5. Step-by-Step Diagnosis
  6. Solution – Primary Fix
  7. Solution – Alternative Approaches
  8. Verification & Acceptance Criteria
  9. Rollback Plan
  10. Prevention & Hardening
  11. Related Errors & Cross-Refs
  12. References & Further Reading

Symptom & Impact

SSH login fails with permission denied despite valid keypair.

Environment & Reproduction

Often occurs after home directory permission changes or sshd config edits.

ssh -vvv user@host
sudo systemctl status ssh --no-pager

Root Cause Analysis

Incorrect file permissions, wrong username, or sshd settings disable key auth.

Quick Triage

Check server logs for exact auth rejection reason.

sudo journalctl -u ssh -n 100 --no-pager
sudo sshd -T | grep -Ei 'pubkeyauthentication|authorizedkeysfile'

Step-by-Step Diagnosis

Validate key files and ownership on target account.

ls -ld ~/.ssh
ls -l ~/.ssh/authorized_keys
namei -l ~/.ssh/authorized_keys
Illustrative mockup for ubuntu-24-04-lts — terminal_or_shell
Diagnostic output for security/ssh-authentication — Illustrative mockup — Progressive Robot

Solution – Primary Fix

Restore canonical SSH permissions and ensure PubkeyAuthentication is enabled.

Still having issues? Our IT Consulting team can diagnose and resolve this for you. Get in touch for a free consultation.

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R $USER:$USER ~/.ssh
sudo systemctl reload ssh
Illustrative mockup for ubuntu-24-04-lts — log_or_console
Resolution output for security/ssh-authentication — Illustrative mockup — Progressive Robot

Solution – Alternative Approaches

Use Match blocks for specific users if global policy conflicts exist.

sudoedit /etc/ssh/sshd_config.d/99-local.conf
sudo sshd -t
sudo systemctl reload ssh

Verification & Acceptance Criteria

Key-based login succeeds without password fallback.

ssh -o PreferredAuthentications=publickey user@host 'id'

Rollback Plan

Restore previous sshd snippets if authentication behavior regresses.

sudo rm -f /etc/ssh/sshd_config.d/99-local.conf
sudo systemctl reload ssh

Prevention & Hardening

Manage sshd config in drop-in files and test with sshd -t before reload.

sudo sshd -t

Related messages include Authentication refused: bad ownership or modes.

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

OpenSSH and Ubuntu server hardening documentation.

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.