Fix: Permission denied (publickey)
The server refused every key your SSH client offered. Find out which key was offered, make sure its public half is on the server for the right user, and check permissions.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
You run ssh, git push or git clone and get:
[email protected]: Permission denied (publickey).
This means the server only accepts key-based login, and none of the keys your client offered matched a public key in that user’s authorized_keys. The word in parentheses is the list of login methods the server still allows. Nothing is wrong with the network: the connection worked, the authentication did not.
Step 1: see what SSH actually tried
Verbose mode prints each key the client offers and how the server responded.
ssh -v [email protected]
# For Git hosts:
ssh -vT [email protected]
Look for lines such as Offering public key: /home/ana/.ssh/id_ed25519 and Authentications that can continue: publickey. If no key is offered at all, your client cannot find one. If a key is offered and then the next method is tried, the server does not know that key.
Step 2: check the usual causes
- Wrong username. Keys are stored per user on the server.
ssh serveruses your local username unless you adduser@or setUserin~/.ssh/config. For Git hosts the user is alwaysgit, as in[email protected]. - The public key is not on the server. Install it with
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@host(needs another way in, such as a password or a console), or add the.pubcontents to your Git host account. - The client offers the wrong key. SSH tries default names such as
id_ed25519andid_rsa, plus whatever is loaded in the agent. Point it at the right file withssh -i ~/.ssh/work_key user@host, or permanently withIdentityFileandIdentitiesOnly yesin~/.ssh/config. - The key is not loaded in the agent. Run
ssh-add -lto list loaded keys andssh-add ~/.ssh/id_ed25519to add yours. - Permissions are too open on the server. With the default
StrictModessetting, the SSH server ignoresauthorized_keysif the home folder,~/.sshor the file itself is writable by others.
Step 3: fix permissions
On your own machine, the private key must be readable only by you, or SSH will refuse to use it and warn about an “UNPROTECTED PRIVATE KEY FILE”:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/config
chmod 644 ~/.ssh/id_ed25519.pub
On the server (as the target user):
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod go-w ~
Step 4: check the server side
If you administer the server, its log usually says exactly why the key was rejected. Depending on the distribution, look at journalctl -u ssh or journalctl -u sshd, or the file /var/log/auth.log. Also confirm the line in authorized_keys is one unbroken line: copying from a terminal sometimes inserts line breaks.
A Git-specific variant
If git push fails but your remote URL starts with git@, the same steps apply. If you would rather use a token over HTTPS, switch the remote with git remote set-url origin https://.... Either way, test the SSH side alone with ssh -T [email protected] before debugging Git itself.
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0053 Set up SSH keys: ssh-keygen, ssh-copy-id and ~/.ssh/config SSH keys let you log in to servers and push to Git hosts without typing a password. Create an ed25519 key, install… Beginner · Step by step · Linux, macOS, Windows Article Keys & config 15 Oct 2026
- 0178 Create a sudo user with an SSH key and disable password login A bash script that creates an admin user in the sudo or wheel group, installs their SSH public key and can switch… Advanced · Step by step · Linux Script Keys & config · Users, sudo & hardening 15 Oct 2026
- 0254 Automate three servers with Ansible: roles, templates, Vault and safe dry runs Build a real Ansible project for two web servers and one database server: inventory groups, SSH keys, roles, templates, handlers, an encrypted… Intermediate · Guided project · Linux, macOS Article Ansible · Keys & config 15 Oct 2026
- 0345 SSH keys: create, copy and use them Generate an ed25519 key pair, install the public key on a server with ssh-copy-id, keep the private key protected with a passphrase… Beginner · Step by step · Linux, macOS, Windows Article Keys & config · SSH 15 Oct 2026
- 0346 The SSH config file: aliases, jump hosts and keys per server Reference for ~/.ssh/config: short names for servers, the right user, port and key per host, ProxyJump through a bastion, connection reuse and… Intermediate · Cheat sheet · Linux, macOS, Windows Article Keys & config · SSH 15 Oct 2026
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +2,916 chars