Permission denied (publickey)
The server rejected every SSH key you offered
Seen in OpenSSH client, git over SSH (GitHub, GitLab, Bitbucket), cloud VMs
The SSH server only accepts key authentication and none of the keys your client offered are authorised for that user.
Common causes
- Your public key is not added to the account (GitHub settings, or ~/.ssh/authorized_keys on the server).
- The client is offering the wrong key, or the key is not loaded in ssh-agent.
- Wrong username: e.g. ubuntu vs ec2-user on cloud images, or anything other than git@ for Git hosts.
- Server-side permissions on ~/.ssh or authorized_keys are too open, so sshd ignores them.
How to fix it
- Run ssh -v user@host to see which keys are offered and whether one is accepted.
- Add your key to the agent (ssh-add ~/.ssh/id_ed25519) or set IdentityFile for the host in ~/.ssh/config.
- For GitHub, test with ssh -T git@github.com after adding the public key to your account.
- On the server: chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys.
Got a different message? Paste it into the error explainer.
Related errors
- error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 · The push is larger than the server or proxy accepts
- error: RPC failed; curl 18 transfer closed with outstanding read data remaining · The connection dropped during a git transfer
- fatal: the remote end hung up unexpectedly · The Git server closed the connection
- kex_exchange_identification: Connection closed by remote host · The SSH server closed the connection before the handshake
- Host key verification failed. · SSH couldn't confirm the server's identity
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! · The server's SSH host key is different from last time
- Unable to negotiate with 203.0.113.10 port 22: no matching host key type found. Their offer: ssh-rsa · The server only offers an old host key type
- Unable to negotiate with 203.0.113.10 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1 · Client and server share no key exchange algorithm
- Received disconnect from 203.0.113.10 port 22:2: Too many authentication failures · The client offered too many keys before the right one
- Connection closed by 203.0.113.10 port 22 · The SSH server ended the session
- npm ERR! code ETIMEDOUT · npm couldn't reach the registry in time
- npm ERR! code ERR_SOCKET_TIMEOUT · The registry connection went silent