Skip to content
ecdsa.com
OpenSSH client (ssh, scp, sftp, git over SSH)SSH

Error message

Permission denied (publickey).

Also printed as

  • git@github.com: Permission denied (publickey).
  • Permission denied (publickey,password).

Prefixed with `user@host:`. The parenthesised list shows the methods the server still allows, e.g. `(publickey,password)` or `(publickey,gssapi-keyex,gssapi-with-mic)`.

What it means

The SSH connection and host verification succeeded, but the server accepted none of the public keys the client offered, and public-key authentication is the only method it allows (the list in parentheses). The client never learns why a key was refused — that reason is only in the server's log. On GitHub, GitLab and Bitbucket the same message means none of your keys is registered on the account (or deploy key) for that repository.

Why it happens

How to fix it

  1. 1.

    See which keys are offered

    `ssh -v` lists every key the client offers and whether the server accepted it; `ssh -G` shows the effective user and identity files after all config is applied.

    bash
    ssh -v deploy@server.example.com 2>&1 | grep -E "Offering|Server accepts|Authentications that can continue|send_pubkey_test"
    ssh-add -l                                  # keys the agent offers
    ssh -G deploy@server.example.com | grep -E "^(user|identityfile|identitiesonly) "
  2. 2.

    Pin the identity per host

    `IdentityFile` plus `IdentitiesOnly yes` offers exactly one key and avoids "Too many authentication failures" with large agents.

    text
    # ~/.ssh/config
    Host server.example.com
      User deploy
      IdentityFile ~/.ssh/deploy_ed25519
      IdentitiesOnly yes
  3. 3.

    Fix the server side and read its log

    Install the public key for the right user with strict modes and check sshd's log for the specific refusal reason.

    bash
    # On the server: install the key and fix modes (sshd ignores keys in group/world-writable paths)
    install -d -m 700 ~/.ssh && cat deploy_ed25519.pub >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys
    sudo journalctl -u ssh --since "10 min ago" | grep -E "Authentication refused|not in PubkeyAccepted|Failed publickey"

Related errors

Browse the full signature error database