Short answer: The SSH error Permission denied (publickey) means the server accepts only key-based login and rejected every key your client offered for that user. Fix it by running ssh -v to see which key is offered, using the correct username and key file, adding the public key to ~/.ssh/authorized_keys and setting permissions to 700 and 600.
Key takeaways
- The server must have your public key, the .pub file, on a single line in the target user’s ~/.ssh/authorized_keys .
- With the default StrictModes yes in sshd_config , sshd ignores authorized_keys if the home directory, ~/.ssh or the file can be written by other users, or if they are owned by someone else.
- When git push or git clone fails with this error, the Git host did not accept your key.
- The OpenSSH 8.8 release notes announced that RSA signatures using the SHA-1 hash, the ssh-rsa algorithm, are disabled by default.
I manage SSH access for many client VPS servers, and this is the error I see after almost every new server, new laptop or new team member. The causes are few and predictable. Below I go from the client side to the server side, show the exact commands, and explain the special cases for new cloud servers, GitHub and old RSA keys.

From my own work: Before changing anything on a server, I keep one working SSH session open in another terminal, or I have the provider’s web console ready. Most lockouts I have been called in to fix happened because someone edited sshd_config or authorized_keys, closed their only session, and then could not get back in.
Common causes at a glance
| Cause | Clue | Fix |
|---|---|---|
| Wrong username | Key works for another user, or new VPS | Use the right user, such as root, ubuntu, ec2-user, admin or deploy |
| Wrong key offered | ssh -v shows a different key file |
Use -i and IdentitiesOnly yes |
| Too many keys in the agent | Too many authentication failures | IdentitiesOnly yes with one IdentityFile |
| Key not on the server | Key offered, server rejects it | Add the public key to authorized_keys |
| Bad permissions or owner | Server log mentions bad ownership or modes | chmod 700 ~/.ssh, chmod 600 authorized_keys |
| Server settings | Root or user blocked, different AuthorizedKeysFile | Check sshd -T output |
| Old RSA signature | No mutual signature algorithm | Use Ed25519 or upgrade the server |
Step 1: debug with ssh -v
# Verbose output shows which keys are offered and what the server says
ssh -v user@203.0.113.10
# Lines to look for:
# debug1: Offering public key: /home/me/.ssh/id_ed25519 ED25519 SHA256:...
# debug1: Authentications that can continue: publickey
# debug1: No more authentication methods to try.
# user@203.0.113.10: Permission denied (publickey).
Verbose mode answers the first big question: is your key being offered at all? If you never see Offering public key with the file you expect, the problem is on your computer. If the key is offered and the server moves on, the problem is on the server. Add -vvv for even more detail.
Step 2: fix the client side (user and key)
First check the username. Cloud images use different default users: Ubuntu images often use ubuntu, Amazon Linux uses ec2-user, Debian images on some providers use admin, and many VPS providers give you root. Logging in as the wrong user with the right key fails with the same message.
Next, make sure the right key is used. If you have many keys loaded in an agent, the server may stop after a few attempts. Pin the key explicitly, as described in the ssh_config manual:
# Use a specific key, and only that key
ssh -i ~/.ssh/client_server -o IdentitiesOnly=yes deploy@203.0.113.10
# Make it permanent in ~/.ssh/config
Host client-prod
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/client_server
IdentitiesOnly yes
Host aliases like this also make jump hosts and multiple clients much easier; see my guide to SSH config files and jump hosts. On Windows, OpenSSH refuses private keys that other users can read and prints an unprotected private key warning; remove inherited permissions so only your account can read the file.
From my own work: The most common cause I see in teams is not a broken key at all. It is a developer with eight keys in their agent, and the server closing the connection before the right one is tried. Adding IdentitiesOnly yes to a Host block fixes it permanently, and it also stops your laptop from showing every key to every server.
Step 3: put the public key in authorized_keys
The server must have your public key, the .pub file, on a single line in the target user’s ~/.ssh/authorized_keys. Copy-paste from emails and chat apps often breaks the line or adds spaces, which silently invalidates it.
# Easiest: copy your public key to the server (needs another way in once)
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@203.0.113.10
# Or append it manually on the server; it must be ONE line
echo 'ssh-ed25519 AAAAC3Nza... me@laptop' >> ~/.ssh/authorized_keys
# Compare fingerprints on both sides
ssh-keygen -lf ~/.ssh/id_ed25519.pub # on your computer
ssh-keygen -lf ~/.ssh/authorized_keys # on the server
The fingerprints must match. If you cannot log in at all, use your provider’s web or recovery console to add the key. My guide to SSH key authentication on Ubuntu covers creating keys and disabling password login safely afterwards.
Step 4: fix permissions and ownership
With the default StrictModes yes in sshd_config, sshd ignores authorized_keys if the home directory, ~/.ssh or the file can be written by other users, or if they are owned by someone else. This often happens after copying files as root.
# On the server, as the target user (or with sudo for that user's home)
chmod go-w ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R "$USER":"$USER" ~/.ssh
# Check the result
ls -ld ~ ~/.ssh ~/.ssh/authorized_keys
If you created the files with sudo, the owner may be root. The chown line fixes that. Run it for the target user, not for root, unless you are configuring root login.
Step 5: check sshd settings and server logs
# Effective server settings (run on the server)
sudo sshd -T | grep -E "pubkeyauthentication|authorizedkeysfile|permitrootlogin|allowusers|allowgroups|pubkeyacceptedalgorithms"
# Live server-side log while you try to log in
sudo journalctl -u ssh -f # Ubuntu and Debian (service name "ssh")
sudo journalctl -u sshd -f # RHEL, Rocky, Alma, Fedora
Look for these settings in the output:
pubkeyauthentication yesmust be enabled.authorizedkeysfilemust point where your key is, normally.ssh/authorized_keys.permitrootloginset tonoblocks root even with a valid key;prohibit-passwordallows root with keys only.allowusersorallowgroupsmust include your user if they are set.- Files in
/etc/ssh/sshd_config.d/can override the main file on modern Ubuntu, so check them too.
The server log usually states the reason directly, such as bad ownership or modes, or a user not allowed because of AllowUsers. After changing settings, run sudo sshd -t to test the syntax before restarting the service. For a full hardening setup, see my guide to hardening OpenSSH on production servers.
Permission denied (publickey) with GitHub and GitLab
When git push or git clone fails with this error, the Git host did not accept your key. Add the public key to your account settings, check that the repository uses an SSH URL, and test:
# Test GitHub authentication
ssh -T git@github.com
# Hi username! You've successfully authenticated, but GitHub does not provide shell access.
# Check which remote URL the repo uses (must be git@github.com:..., not https://)
git remote -v
GitHub’s own troubleshooting page covers agent and key checks in detail. For CI servers, use a deploy key per repository rather than a personal key, and give it read-only access unless it must push.
Old RSA keys and OpenSSH 8.8
The OpenSSH 8.8 release notes announced that RSA signatures using the SHA-1 hash, the ssh-rsa algorithm, are disabled by default. An RSA key itself still works with modern servers, which use rsa-sha2-256 or rsa-sha2-512, but connecting from a new client to a very old server can fail. The real fix is to upgrade the server or move to an Ed25519 key; a per-host override is a temporary workaround:
# Generate a modern key if you only have an old RSA one
ssh-keygen -t ed25519 -C "me@laptop"
# Temporary workaround for a legacy server you cannot upgrade yet (one host only)
Host legacy-box
HostName 198.51.100.7
PubkeyAcceptedAlgorithms +ssh-rsa
HostkeyAlgorithms +ssh-rsa
Generate keys with ssh-keygen and protect the private key with a passphrase.
From my own work: When I take over a client server, I replace any shared key that several people used with one key per person and add a comment with their name to each line in authorized_keys. When someone leaves, removing access is one line, and nobody has to rotate a key that half the team depends on.
If you are locked out completely
- Open the provider’s web console, rescue mode or recovery console.
- Log in as root or the console user, then fix authorized_keys, ownership and permissions for your user.
- Check
sshd -Tand the files insshd_config.dfor settings that block you. - Check that a firewall or Fail2ban has not banned your IP; my guides to the UFW firewall cover the rules.
- Test login from a second terminal before closing the console.
Permission denied (publickey) checklist
- Run
ssh -vand confirm the expected key is offered. - Use the correct username for the server or image.
- Pin the key with IdentityFile and IdentitiesOnly yes.
- Public key on one line in the user’s authorized_keys, fingerprints match.
- Home not group-writable, ~/.ssh 700, authorized_keys 600, correct owner.
- PubkeyAuthentication, AuthorizedKeysFile, PermitRootLogin and AllowUsers checked with sshd -T.
- Server log read while you try to connect.
- Git hosts: key added to the account and SSH remote URL.
- Old servers: Ed25519 key or a temporary per-host ssh-rsa override.
- Keep a second session or console open while you change anything.
Want this done on your own server or site?
I am Saizul Amin, a web developer and technical SEO consultant. I set up and harden VPS servers, migrate WordPress sites, fix indexing problems and build automations. See my portfolio or get in touch.
FAQ
What does Permission denied (publickey) mean?
It means the SSH server only accepts key-based login and none of the keys your client offered were accepted for that user. Either the wrong user or key was used, the public key is not in the user’s authorized_keys file, or file permissions or server settings reject it.
How do I fix Permission denied (publickey) on a new VPS?
Check you are using the provider’s default user, such as root, ubuntu, ec2-user or admin, and the key you selected when creating the server. Run ssh -v to confirm the key is offered, and use the provider’s web console to fix authorized_keys if needed.
Why does git push say Permission denied (publickey)?
GitHub, GitLab or Bitbucket did not accept your key. Add your public key to your account, check the repository uses an SSH remote URL, and test with ssh -T git@github.com. If you have several keys, set the right IdentityFile in ~/.ssh/config.
What permissions should .ssh and authorized_keys have?
With the default StrictModes setting, the home directory must not be writable by group or others, ~/.ssh should be 700 and ~/.ssh/authorized_keys should be 600, all owned by the user. Otherwise sshd ignores the file.
Why does my old RSA key stop working?
OpenSSH 8.8 disabled RSA signatures using SHA-1 (ssh-rsa) by default. Modern clients and servers use rsa-sha2-256 or rsa-sha2-512 with the same RSA key, but very old servers only support ssh-rsa. Upgrade the server or switch to an Ed25519 key.
Sources
- OpenSSH: sshd_config manual
- OpenSSH: ssh_config manual
- OpenSSH 8.8 release notes
- GitHub Docs: Error: Permission denied (publickey)
- OpenSSH: ssh-keygen manual

Saizul Amin is a web developer, AI automation engineer and technical SEO consultant from Dhaka, Bangladesh (B.Sc. in CSE, BUBT). Since 2017 he has worked in digital marketing, WordPress, IT infrastructure and server administration, including the bilingual SHR Bangladesh website for DGHS, WordPress sites for UK and US clients, and the ShobFree tools platform. He runs this blog on his own Ubuntu VPS with nginx, Redis and CloudPanel, and tests the guides here on it. Portfolio: saizul.com

