SSH refuses your key and ends with Permission denied (publickey)
user@203.0.113.10: Permission denied (publickey).Short answer
The server accepted the connection but found no key it would take. Run ssh -vvv and read what the client offered. Usually the right key is not offered, you are logging in as the wrong account, the home folder or authorized_keys has permissions StrictModes rejects, or sshd_config forbids the user or the key's signature type.
Fix it fast
1Find out which cause you have
Connect with verbose output and look at three things: which key files the client lists, whether any line says Offering public key, and what the server answers after it. The server's own reason is only in its log, so read that too if you have a console or another way in.
ssh -vvv user@203.0.113.10 2>&1 | grep -E "identity file|Will attempt key|Offering public key|Server accepts key|Authentications that can continue|no mutual signature" # on the server (Debian and Ubuntu use the unit name ssh, RHEL-style systems use sshd) sudo journalctl -u ssh -n 30 --no-pager2Match what you see, then jump to its fix
- 1
ssh -v prints no Offering public key line for the key you expect, or offers several other keys first and the server stops after its attempt limit.The client never offers the right keyFix - 2
The key is offered but never accepted, and the server log says Invalid user, or the key sits in a different account's authorized_keys.You are logging in as an account that does not hold the keyFix - 3
The server log says Authentication refused: bad ownership or modes for directory (or for file) and names a path.Permissions or ownership make sshd ignore authorized_keysFix - 4
The server log says User deploy not allowed because not listed in AllowUsers, or the effective settings show PubkeyAuthentication no or an AuthorizedKeysFile path you did not expect.sshd_config blocks the user, the method or the key locationFix - 5
Your key type is RSA, the client is OpenSSH 8.8 or newer, the server is old, and the key is rejected even though it is in authorized_keys and the modes are right.An older server only accepts the SHA-1 RSA signature that new clients no longer sendFix
- 1
What does the error look like?
user@203.0.113.10: Permission denied (publickey).user@203.0.113.10: Permission denied (publickey,password).debug1: Authentications that can continue: publickeyAuthentication refused: bad ownership or modes for directory /home/user (in the server log)
Cause 1 of 5
The client never offers the right key
1Check
ssh tries the default key files, keys held by ssh-agent and any IdentityFile lines for the matching Host block. If your key has another name, or the agent holds many keys, the right one may never be sent. Compare the fingerprint of your key with the keys the server has on file for that account.
ssh-add -l
ssh-keygen -lf ~/.ssh/id_ed25519.pub
# on the server, as the target user:
ssh-keygen -lf ~/.ssh/authorized_keys2Fix
Name the key explicitly and tell ssh to send only that one. IdentitiesOnly yes stops the agent's other keys from being offered first. If the fingerprint is not in authorized_keys at all, add the public key to the right account (not the private one).
# ~/.ssh/config
Host myserver
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
# one-off
ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes deploy@203.0.113.103Verify
ssh -v now shows Offering public key for that file, followed by Server accepts key.
ssh -v myserver 2>&1 | grep -E 'Offering public key|Server accepts key|Authenticated to'Confirmed by man.openbsd.org
Cause 2 of 5
You are logging in as an account that does not hold the key
1Check
authorized_keys is read from the home folder of the account you name, not of the account you have on your laptop. Without user@ in the command, ssh sends your local user name. Cloud images often disable direct root login and create another default account, so look at what the provider's console says.
ssh -v user@203.0.113.10 2>&1 | grep -i "Authenticating to"
# on the server
getent passwd deploy
sudo ls -l /home/deploy/.ssh/authorized_keys2Fix
Use the account that owns the key, with user@host or a User line in ~/.ssh/config. To give a new account access, put the public key in that account's authorized_keys.
ssh deploy@203.0.113.10
# add a key for another account (run as root on the server)
install -d -m 700 -o deploy -g deploy /home/deploy/.ssh
cat >> /home/deploy/.ssh/authorized_keys # paste the .pub line, then Ctrl-D
chown deploy:deploy /home/deploy/.ssh/authorized_keys
chmod 600 /home/deploy/.ssh/authorized_keys3Verify
The login succeeds, and whoami on the server prints the account you meant.
ssh deploy@203.0.113.10 whoamiConfirmed by man.openbsd.org
Cause 3 of 5
Permissions or ownership make sshd ignore authorized_keys
1Check
StrictModes is on by default. sshd then checks modes and ownership of the user's files and home directory before accepting a key, so a home folder or .ssh folder that other users can write to is refused. Typical causes are a recursive chmod 777, a home folder created by root, or files copied in by root.
namei -l /home/deploy/.ssh/authorized_keys
sudo sshd -T | grep -i strictmodes2Fix
Make the account own its home, .ssh and authorized_keys, and take write access away from everyone else. Do not turn StrictModes off; fixing the modes is the answer.
sudo chown -R deploy:deploy /home/deploy/.ssh
sudo chmod go-w /home/deploy
sudo chmod 700 /home/deploy/.ssh
sudo chmod 600 /home/deploy/.ssh/authorized_keys3Verify
namei shows no group- or world-writable folder in the path, and the next login passes.
namei -l /home/deploy/.ssh/authorized_keysConfirmed by man.openbsd.org
Cause 4 of 5
sshd_config blocks the user, the method or the key location
1Check
Read the settings sshd actually uses, not the file you edited. sshd -T prints the effective values after Include files and Match blocks are applied. For each setting the first value found wins, and files in sshd_config.d are read in name order, so an earlier file can override a later one.
sudo sshd -T -C user=deploy,host=client.example,addr=198.51.100.7 | grep -iE '^(pubkeyauthentication|authorizedkeysfile|allowusers|denyusers|allowgroups|permitrootlogin)'
sudo grep -rnE 'AllowUsers|PubkeyAuthentication|AuthorizedKeysFile' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/2Fix
Add the user to AllowUsers (or AllowGroups), enable public key authentication, and put the change in a file that sorts before any file that sets the same keyword. Test the syntax before reloading and keep your current session open until a second login works.
sudo tee /etc/ssh/sshd_config.d/00-access.conf >/dev/null <<'EOF'
PubkeyAuthentication yes
AllowUsers deploy
EOF
sudo sshd -t && sudo systemctl reload ssh # unit is sshd on RHEL-style systems3Verify
A new terminal logs in with the key while the old session is still open; sshd -T shows the new values.
sudo sshd -T | grep -iE '^(pubkeyauthentication|allowusers)'Confirmed by man.openbsd.org
Cause 5 of 5
An older server only accepts the SHA-1 RSA signature that new clients no longer send
1Check
OpenSSH 8.8 turned off RSA signatures that use SHA-1. Existing RSA keys keep working with the SHA-256 and SHA-512 signature types, but a server too old to understand those cannot verify them. Check the server's version banner.
ssh -v user@203.0.113.10 2>&1 | grep -iE "remote software version|server accepts key|no mutual"2Fix
The proper fix is to update the server, or to switch to an Ed25519 key. If you must reach the old host first, allow SHA-1 RSA for that one host only, as a temporary measure, and remove the lines afterwards.
ssh-keygen -t ed25519 -C "laptop-2026"
# temporary, ~/.ssh/config
Host old-host
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa3Verify
The old host accepts the new Ed25519 key, and the +ssh-rsa lines are gone from your config.
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 user@old-host trueConfirmed by openssh.org
How do I stop it coming back?
- Keep a Host block per server in ~/.ssh/config with User, IdentityFile and IdentitiesOnly yes, so the intended key is always the one sent.
- After editing sshd settings, run sshd -t, reload, and open a second session before closing the first.
- Use Ed25519 keys and keep servers on a supported OpenSSH release.
- Keep a provider console or a second access path so a bad sshd change cannot lock you out.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Security
AuthenticationException: your certificate validation callback returned false
System.Security.Authentication.AuthenticationException
This message means a validation callback was installed, yours or one a library added, and it returned false.
3 causes, each with a fixSecurity
SSH to an EC2 instance fails with Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
ec2-user@ec2-203-0-113-25.compute-1.amazonaws.com: Permission denied (publickey).
On EC2 this error almost always means the instance did not accept your key for that user.
3 causes, each with a fixSecurity
gcloud init cannot finish the sign-in step
Enter authorization code
gcloud init signs in through a browser.
3 causes, each with a fixSecurity
A GitHub Actions SSH deploy step cannot log in to the server
ssh: handshake failed: ssh: unable to authenticate
The runner reached your server but the server refused the login.
4 causes, each with a fixSecurity
SSH to GitHub asks to confirm the host, or hangs on that prompt
ED25519 key fingerprint is SHA256:
SSH has never seen github.com from this machine, so it asks you to trust the server key.
2 causes, each with a fixSecurity
A GUI program over SSH says it cannot open the display
cannot open display:
ssh must forward X11 and the remote sshd must allow it.
3 causes, each with a fix