SSH permission denied (publickey) means you reached the server and the SSH handshake worked, but the server rejected every public key your client offered. The usual causes are a key missing from authorized_keys, wrong file permissions, the wrong user or key, or a key the client never offered. Run ssh -v to see which keys were offered, then check the server log and the key files.
Key takeaways
- The error means authentication failed, not that the network or SSH service is down.
- Run ssh -v first: it shows whether your key was offered and rejected, or never sent at all.
- The most common fixes are copying the right public key to authorized_keys and setting permissions to 700 and 600.
You type ssh user@server, wait a second, and get one line back: Permission denied (publickey). No hint about which key failed, which file is wrong, or which side is at fault. That silence is deliberate — the server tells an unauthenticated stranger as little as possible — but it also leaves you guessing.
What does SSH permission denied (publickey) mean?
It means you reached the server, the SSH handshake succeeded, and authentication failed. The server checked the public keys your client offered and accepted none of them for that user.
The text in brackets is the useful part. It lists the authentication methods the server still accepts after the failure. If it says only (publickey), password login is disabled, so a key is the only way in and no client-side change can work around that. If it says (publickey,password), a password login was possible in principle but was not attempted or also failed.
This error is different from the look-alikes. Connection refused means SSH is not listening or a firewall blocked port 22. Connection timed out means the server was unreachable. Host key verification failed concerns the server's key in your known_hosts file, not your key. And Permission denied, please try again without brackets usually means a wrong password.
How do you diagnose SSH permission denied (publickey)?
Run the same command with verbose output before changing anything. One -v is usually enough; -vvv adds more detail if you need it.
ssh -v user@your-server
Skip the key-exchange noise and look for the lines after Authentications that can continue. Three patterns cover almost every case, and each points at a different fix.
If you have server access, check the server log too — it names the cause the client never sees. On Debian and Ubuntu it is /var/log/auth.log; on Red Hat, Rocky and AlmaLinux it is /var/log/secure.
Search for sshd lines around the time of the failed login. A line such as Authentication refused: bad ownership or modes for /home/user/.ssh/authorized_keys is the answer. Key hygiene belongs on your small business cybersecurity checklist alongside updates and backups.
What are the most common causes?
Almost every case comes down to one of seven causes. Work through them in this order, because the first three account for most failures.
| Cause | What you see | Fix |
|---|---|---|
| Key not on the server | Key offered and rejected | Copy the public key to authorized_keys |
| Wrong permissions | Key offered and rejected; log says bad modes | chmod 700 ~/.ssh and 600 authorized_keys |
| Wrong user or host | Key offered and rejected | Check the username and hostname |
| Wrong key offered | An unexpected key in ssh -v | Use -i or IdentityFile to pin the key |
| Agent has no key | No Offering line; agent empty | ssh-add ~/.ssh/id_ed25519 |
| Key type rejected | Old ssh-rsa key skipped | Generate an Ed25519 key |
| Too many keys | Too many authentication failures | IdentitiesOnly yes in config |
Is your public key actually on the server?
This is the most common cause for a new server or a new key: the public key was never copied to the remote server, or it went into the wrong user's file.
If you still have password or console access, copy it with ssh-copy-id, which creates the directory, appends the key and sets permissions in one step:
ssh-copy-id user@your-server
If ssh-copy-id is not available, copy it manually. The command below creates ~/.ssh, appends the key and sets the file to 600:
cat ~/.ssh/id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Then verify on the server that the key is really there and matches your local public key. Compare fingerprints rather than eyeballing long key strings:
ssh-keygen -lf ~/.ssh/id_ed25519.pub
ssh-keygen -lf ~/.ssh/authorized_keys
A frequent mistake is copying the private key instead of the .pub file, or copying a key from a different laptop. The private key never belongs on the server. For cloud servers, check the provider console too: some providers let you add a key through instance metadata, which writes it into authorized_keys for you.
Are the file permissions wrong?
SSH is strict about permissions on purpose. If authorized_keys or its parent directories are too open, the server silently ignores the file and rejects the key. This is enforced by StrictModes yes in /etc/ssh/sshd_config, which is the default.
On the remote server, the correct settings are:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/id_ed25519
chmod 755 ~
That last line matters more than people expect: if your home directory is writable by group or others, the server may refuse the key even when .ssh itself is correct. Ownership matters too. If you created ~/.ssh or authorized_keys with sudo, root owns them and the server refuses to use them. Fix ownership with chown -R user:user ~/.ssh, replacing user with your username.
On your local machine, the private key must also be restricted: chmod 600 ~/.ssh/id_ed25519 (or 400). If it is too open, your own client refuses to load it and warns you in the verbose output. Never set permissions to 777 on any SSH file as a "fix" — that is exactly what the server rejects.
Are you using the wrong user, host or key?
A key only works for the user whose authorized_keys contains it. Logging in as root when the key is under deploy, or as ubuntu when it is under ec2-user, fails every time — and the error looks identical to a broken key.
Check the username in the verbose output: Authenticating to 203.0.113.10:22 as 'deploy'. Cloud images each have their own default user: Amazon Linux uses ec2-user, Ubuntu images use ubuntu, and Debian images use admin or debian. If you are unsure, check your provider's documentation for the image you launched.
Also check that your client offered the key you intended. If you have several keys, or a key with a non-default name such as id_work, SSH may try the defaults first and never reach yours. Point at it explicitly:
ssh -i ~/.ssh/id_work user@your-server
Better, pin it in ~/.ssh/config so you do not need the flag every time:
Host myserver
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_work
IdentitiesOnly yes
IdentitiesOnly yes stops the agent offering every key it holds, which also prevents the "too many authentication failures" disconnect. If a host alias in your config points at the wrong hostname or user, that is the bug — verify the alias before changing keys.
Is the SSH agent the problem?
If your key has a passphrase, the agent holds the unlocked key so you are not asked every time. If the agent is not running, or the key was never added, the client may offer nothing and fail.
Check what the agent holds:
ssh-add -l
If the list is empty, or you see The agent has no identities, add the key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
On macOS, keys can be stored in the keychain with ssh-add --apple-use-keychain. On Windows, the OpenSSH Authentication Agent service must be running for ssh-add to work. A related trap: the server accepted the key, but the client could not unlock it to finish the login — loading the key into the agent solves that too.
If you connect through a jump host or a script, check that agent forwarding is not the issue. Forwarding your agent to an untrusted server exposes your keys to that server, so use ProxyJump instead of -A where you can. Our guide to securing your Wi-Fi covers the network side of remote access hygiene.
Is your key type or algorithm rejected?
Modern OpenSSH servers reject old signature algorithms. The best-known case is RSA keys using SHA-1 signatures (ssh-rsa), which OpenSSH disabled by default in version 8.8. A key that worked for years can suddenly stop after a server upgrade, with no change on your side.
The fix is to generate a modern key rather than re-enabling a weak algorithm:
ssh-keygen -t ed25519 -C "[email protected]"
Ed25519 is the recommended default: short keys, fast, and widely supported. If a legacy system cannot use Ed25519, generate RSA with at least 3072 bits using ssh-keygen -t rsa -b 4096. Check what key types your server accepts in /etc/ssh/sshd_config under PubkeyAcceptedKeyTypes and HostKeyAlgorithms, and check the client side in ssh_config.
Also confirm the key file is not corrupted or in the wrong format. A private key that begins with -----BEGIN OPENSSH PRIVATE KEY----- is normal; a PuTTY .ppk file must be converted with PuTTYgen before OpenSSH can use it. If ssh-keygen -y -f ~/.ssh/id_ed25519 prints the matching public key, the private key file itself is readable. The OpenSSH manual pages document ssh-keygen, ssh-agent and the sshd_config options mentioned here.
What about GitHub, GitLab and cloud servers?
The same error appears in different places, and each has its own common cause. On GitHub, test the connection directly:
ssh -T [email protected]
A successful test prints a greeting with your username. If it fails, check that the public key is added under your GitHub account settings, that the agent holds the key, and that your config has an IdentityFile for github.com. GitHub's own troubleshooting guide covers this exact error, as linked in our sources. The same steps apply to GitLab and Bitbucket, with their own key settings pages.
On AWS EC2, the usual causes are the wrong default user, the wrong key pair, or a .pem file with loose permissions — set it to 400 with chmod 400 key.pem. On a server you rebuilt, authorized_keys starts empty, so re-add the key through the console or instance metadata.
If you edited sshd_config — for example to disable password login — always test the config with sshd -t and keep a second session open before restarting the service, or you can lock yourself out. GitHub documents the same error for its own service in its permission denied (publickey) troubleshooting guide.
What is the step-by-step fix checklist?
Work through this checklist top to bottom, in order, and stop as soon as login succeeds. Most cases are fixed by step five.
- Run
ssh -v user@serverand note which keys were offered and whether any were accepted. - Confirm the username, hostname and port. Try the default user for your cloud image.
- Check the server log (
/var/log/auth.logor/var/log/secure) for the exact refusal reason. - Verify the public key is in the right user's
~/.ssh/authorized_keysand the fingerprints match. - Set permissions:
700on~/.ssh,600onauthorized_keysand the private key,755on home. - Fix ownership: the files must belong to the login user, not root.
- Load the key into the agent with
ssh-add, or pin it with-iorIdentityFile. - If the key is an old RSA key, generate an Ed25519 key and add the new public key.
- Add
IdentitiesOnly yesif the agent offers too many keys. - Test the config with
sshd -tafter anysshd_config ...[truncated 1792 chars]code> change, and keep a spare session open while you restart sshd.
If login still fails after all ten steps, the cause is usually server-side configuration: check PubkeyAuthentication and AuthorizedKeysFile in /etc/ssh/sshd_config, and confirm the account is not locked with passwd -S user.
How do you prevent SSH permission denied (publickey) in future?
Preventing the error is mostly about key management. Generate one key per device, name keys clearly, and keep a list of which public keys belong on which servers.
- Use Ed25519 keys with a passphrase. A passphrase protects the key if the laptop is stolen, and the agent means you type it once per session.
- Keep a backup of your public keys, not your private keys. Public keys can be re-added anywhere; a private key should exist in exactly one place, plus an encrypted backup you control.
- Remove keys when people leave. Stale keys in
authorized_keysare a standing access path. Review the file when a contractor finishes or an employee leaves. - Use SSH certificates or a bastion host for teams. At scale, managing individual keys in files does not scale, and certificates expire automatically.
- Test new keys before you close your old session. Add the new public key, log in with it in a second terminal, and only then remove the old one.
For a wider review of access controls, our small business cybersecurity checklist covers keys, MFA and backups together.
The security baseline product page explains how Cysoro tracks these controls across a team.
The bottom line
SSH permission denied (publickey) is an authentication failure, not a network failure. Run ssh -v, find which pattern you are in, then check the key, the user, the permissions and the agent in that order.
Most cases end with a key copied to the right file or a permission fixed to 700 and 600. Fix the key, keep password login off, and you keep the convenience of key login without opening the server to password guessing.
Frequently asked questions
What does SSH permission denied (publickey) mean?
It means your SSH client connected to the server, but the server did not accept any of the public keys offered for that user. The text in brackets lists the authentication methods the server still accepts. If it says only publickey, password login is disabled, so a key is the only way in.
Why does SSH say permission denied even though my key is correct?
The key may be in the wrong user's authorized_keys file, the file permissions may be too open so the server ignores it, or your client may be offering a different key than the one on the server. Run ssh -v to see which key was actually offered, and compare its fingerprint with the server copy.
What permissions should .ssh and authorized_keys have?
The .ssh directory should be 700, authorized_keys should be 600, and your private key should be 600. The home directory should not be writable by group or others. OpenSSH ignores authorized_keys when these are too open, under the StrictModes setting that is on by default.
How do I fix permission denied (publickey) on GitHub?
Check that your public key is added to your GitHub account, test with ssh -T [email protected], and make sure your SSH agent has the key loaded with ssh-add -l. If you use a non-default key file, add an IdentityFile entry for github.com in ~/.ssh/config.
How do I fix permission denied (publickey) on AWS EC2?
Use the right default user for the image, such as ec2-user for Amazon Linux or ubuntu for Ubuntu, and the key pair you selected when launching the instance. Check that the .pem file has 400 permissions and that you are connecting to the right instance and region.
Does ssh -v show my private key?
No. Verbose output shows key file names, key types and fingerprints, and which keys were offered and accepted or rejected. It does not print private key material, so it is safe to share the relevant lines when asking for help, after removing hostnames and usernames if you prefer.
What is the difference between permission denied (publickey) and permission denied, please try again?
Permission denied (publickey) is a public-key authentication failure. Permission denied, please try again, without brackets, usually means a wrong password. Host key verification failed is different again: it concerns the server's key in your known_hosts file, not your key.
Can I get locked out by too many SSH key attempts?
Yes. If your agent offers many keys, the server may disconnect after MaxAuthTries with too many authentication failures. Limit the keys offered with IdentitiesOnly yes and an IdentityFile in your SSH config, or remove unneeded keys from the agent.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against OpenSSH documentation and the Linuxize and GitHub troubleshooting guides.
How we write and fact-check →