`ssh deploy@server01` fails with `deploy@server01: Permission denied (publickey).`
BeginnerTroubleshootingSSH, sudo and authentication
Answer
Likely causes → The client offers the wrong key, the public key isn't in the right authorized_keys, or permissions on ~, ~/.ssh or authorized_keys are too open so sshd ignores them.
Diagnose →
ssh -v deploy@server01 2>&1 | grep -E 'Offering|Authentications|identity file'
# on the server (console or another account)
sudo ls -ld /home/deploy /home/deploy/.ssh /home/deploy/.ssh/authorized_keys
sudo journalctl -u sshd -n 30 | grep -i deploy
Fix →
sudo chmod go-w /home/deploy
sudo chmod 700 /home/deploy/.ssh
sudo chmod 600 /home/deploy/.ssh/authorized_keys
sudo chown -R deploy:deploy /home/deploy/.ssh
Use the correct key: ssh -i ~/.ssh/deploy_ed25519 deploy@server01.
Prevent → Create keys with automation (Ansible authorized_key) which sets modes correctly.
More on SSH, sudo and authentication
Permissions on `~/.ssh` are correct, but you still get `Permission denied (publickey)` and the server log says `Authentication refused: bad ownership or modes for directory /home/deploy`.IntermediateKey auth fails only on RHEL with SELinux enforcing; the server logs show nothing unusual about modes.IntermediateAfter upgrading the client to a new OpenSSH, connections to an old appliance fail with `no matching host key type found. Their offer: ssh-rsa,ssh-dss`.IntermediateA user's RSA key stopped working against a new server: the server log says `userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms`.IntermediateSSH login takes 20–30 seconds before the password or key prompt appears.IntermediateSSH fails immediately with `kex_exchange_identification: read: Connection reset by peer`.Advanced