An SSH Permission denied (publickey) error means the connection reached authentication, but the login did not complete with an accepted key. It’s different from a timeout or a refused connection—and it doesn’t necessarily mean your key is missing.
The fastest way to narrow it down is to find out which account and key your client actually used, then check whether the server recognizes that key for that account.
Start with the client’s authentication trace
Run the failing connection with verbose output:
ssh -vv user@host
Replace user@host with the account and host you’re trying to reach. Focus on the authentication lines rather than the entire connection trace.
-
Offering public keymeans the client proposed that key. It does not mean the server accepted it. -
Server accepts keymeans the server recognized the public key, but authentication can still fail afterward. -
Authenticated to ... using "publickey"confirms that public-key authentication succeeded.
If the trace doesn’t show the key you expected, check the client configuration before changing anything on the server. If the expected key is offered but rejected, check the account, the server’s authorized keys, and the server-side logs.
Verify the account, host, and identity
A host alias can hide the username, hostname, port, or key selected by SSH. Print the effective configuration without attempting a login:
ssh -G myserver | grep -E '^(hostname|user|port|identityfile|identitiesonly|proxyjump) '
On Windows PowerShell, use:
ssh -G myserver | Select-String '^(hostname|user|port|identityfile|identitiesonly|proxyjump) '
Confirm that the effective hostname and username are correct. A key authorized for deploy will not automatically work when you connect as root. Cloud image usernames also vary, so check your provider or image documentation rather than guessing.
To test one specific identity and avoid offering other keys from your agent, try:
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 user@host
Use the private-key file, without the .pub suffix. On Windows PowerShell, a typical path is "$HOME\.ssh\id_ed25519".
If the explicit command works, set the identity for that host in ~/.ssh/config:
Host myserver
HostName server.example.com
User deploy
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
This keeps the fix scoped to the host instead of changing key selection globally.
Check that the server has the matching public key
The server checks keys for the account you requested. A valid private key can still fail if its public half is missing from that account’s authorized keys—or if the server reads a different authorized-keys file than you expect.
On the client, print the fingerprint of the public key paired with your private key:
ssh-keygen -lf ~/.ssh/id_ed25519.pub
On the server, use an existing administrator session or provider console to check the target account’s authorized keys:
sudo ssh-keygen -lf /home/deploy/.ssh/authorized_keys
Replace deploy with the actual account. Compare the SHA256 fingerprints; authorized_keys can contain more than one key. These are user key fingerprints, not the server’s host-key fingerprint shown when you first connect.
If the key is missing and you have a working login, ssh-copy-id can install its public half:
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@host
If no SSH login works, that command cannot bypass authentication. Use an authorized recovery console or administrator session to append the public key to the correct file. Never copy your private key to the server or overwrite an existing authorized_keys file just to add one key.
Windows OpenSSH servers have a path difference worth checking: when the login account is in the Administrators group and the default matching rule applies, authorized keys are read from C:\ProgramData\ssh\administrators_authorized_keys rather than the user’s usual .ssh directory.
Inspect server-side permissions and logs
On a Linux server, check the target account’s home directory and SSH files:
namei -l /home/deploy/.ssh/authorized_keys
ls -ld /home/deploy /home/deploy/.ssh /home/deploy/.ssh/authorized_keys
Typical secure permissions are 700 on .ssh and 600 on authorized_keys. The home directory must not be writable by unrelated users. With the default StrictModes yes, OpenSSH checks ownership and permissions before trusting these files.
Make changes only after confirming the account and paths. For example, these commands assume /home/deploy is the correct home directory and that the account’s primary group is also deploy:
sudo chmod go-w /home/deploy
sudo chmod 700 /home/deploy/.ssh
sudo chmod 600 /home/deploy/.ssh/authorized_keys
sudo chown deploy:deploy /home/deploy/.ssh /home/deploy/.ssh/authorized_keys
Check the account’s actual group first with id deploy. On a Linux or macOS client, a private key typically needs chmod 600 ~/.ssh/id_ed25519. Windows uses NTFS ACLs rather than Unix chmod; inspect them with icacls instead of applying Linux permission commands.
When client output doesn’t reveal why a key was rejected, server logs can help. On Ubuntu or Debian with systemd:
sudo journalctl -u ssh --since '15 minutes ago' --no-pager | tail -n 80
The service may be called sshd on Fedora/RHEL-style systems. Look for messages about bad ownership or modes, a disallowed account, an unreadable authorized-keys file, or a signature-algorithm mismatch. If you need to change server configuration, keep a working administrator session open and test a separate login before closing it.
Avoid risky shortcuts
Don’t disable StrictModes, use chmod 777, or enable password login globally just to make the error disappear. Those changes can weaken access controls or create a larger problem than the one you’re debugging.
An RSA key is not automatically outdated, either. Compatibility problems can involve the older ssh-rsa signature based on SHA-1, which is separate from whether the key itself is RSA.
If SSH is not installed or listening on an Ubuntu server, that’s a connection setup problem rather than a public-key rejection; check how to enable SSH on Ubuntu before troubleshooting authentication. If you’re connecting from Windows and suspect the client or its key handling, compare Windows SSH client options—but first verify the same connection from a regular terminal.
A quick order of operations
- Run
ssh -vvand identify the key offered. - Use
ssh -Gto confirm the effective host, username, and identity. - Test the intended private key explicitly with
IdentitiesOnly=yes. - Compare its public-key fingerprint with the target account’s authorized keys.
- Check server-side permissions and logs if the key is still rejected.
If the key is offered but not accepted, focus on the server’s account, key file, access rules, and logs. If the server accepts it but login still fails, look at signing, passphrase handling, or requirements for an additional authentication method. Keep any working session open while testing a fix.
I originally published a more detailed version of this guide on the ShadeTerm blog.
I'm also building ShadeTerm — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.
Top comments (0)