GrepBoard/Manuals
605 manuals ·

Fix git@github.com Permission denied (publickey)

·Tested on Ubuntu 24.04 (Docker) · OpenSSH 9.6p1 · git 2.43.0 · 2026-10·Test scope ↓·6 steps

git@github.com Permission denied (publickey): ssh offered no key GitHub accepts. Run ssh -vT to see the keys tried, then check key, agent and user.

output
git@github.com: Permission denied (publickey).fatal: Could not read from remote repository. Please make sure you have the correct access rightsand the repository exists.

GitHub only accepts public-key authentication, and none of the keys ssh offered is registered to an account. Run ssh -vT git@github.com to see which key files were actually tried; if there are none, create and register one, otherwise check the agent, the file name and sudo. If you run your own sshd and see the same message on the server side, read Find the cause of SSH Permission denied (publickey) instead — this page is about the client connecting to GitHub. If you use an HTTPS remote (https://github.com/…) instead of SSH and your password is refused, see Fix GitHub Support for password authentication was removed.

[1] Test with ssh alone, without git. If the result is the same, the problem is authentication, not repository permissions.

console
$ ssh -T git@github.com; echo "exit=$?"git@github.com: Permission denied (publickey).exit=255

On success GitHub answers Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access. (official docs). If you get that and only git clone fails, the account lacks access to the repository or the remote URL is wrong.

[2] Check that the user is git. GitHub takes every SSH connection as the git user. A remote like your-username@github.com:… is rejected even with the right key.

console
$ git remote -v

If the URL is not of the form git@github.com:<owner>/<repo>.git, fix it with git remote set-url origin git@github.com:<owner>/<repo>.git.

[3] See which keys ssh tried. This is from an environment with no keys at all.

console
$ ssh -vT git@github.com 2>&1 | grep -E "Connecting to|identity file|Authentications that can continue|Trying private key|Offering|No more authentication|Permission denied"debug1: Connecting to github.com … port 22.debug1: identity file /root/.ssh/id_rsa type -1debug1: identity file /root/.ssh/id_rsa-cert type -1…debug1: identity file /root/.ssh/id_ed25519 type -1…debug1: Authentications that can continue: publickeydebug1: Trying private key: /root/.ssh/id_rsa…debug1: Trying private key: /root/.ssh/id_dsadebug1: No more authentication methods to try.git@github.com: Permission denied (publickey).

How to read it:

What you seeMeaning
Only identity file … type -1 and Trying private key, no Offering public keyNo key file at those paths. ssh looks only for the seven default names
Offering public key: … and then the next keyA key was offered but it is not registered to a GitHub account
Paths under /root/.ssh/…You ran as root, e.g. sudo git …. Your own user's keys are not used
Stuck at Connecting to … port 22It never reached authentication. Port 22 may be blocked — see [6]

GitHub's docs also say not to use sudo with Git: a key generated without sudo is not used by sudo git push.

[4] Point ssh at a key with a non-default name. These are the only files ssh picks up on its own:

console
$ ssh -G github.com | grep -E "^(user|hostname|port|identityfile|identitiesonly) "…user roothostname github.comport 22identitiesonly noidentityfile ~/.ssh/id_rsaidentityfile ~/.ssh/id_ecdsaidentityfile ~/.ssh/id_ecdsa_skidentityfile ~/.ssh/id_ed25519identityfile ~/.ssh/id_ed25519_skidentityfile ~/.ssh/id_xmssidentityfile ~/.ssh/id_dsa

If you named it ~/.ssh/github_work, test once with ssh -i ~/.ssh/github_work -T git@github.com, then put it in your config. With several accounts and keys, IdentitiesOnly yes makes ssh offer only the listed key.

~/.ssh/config
Host github.com    User git    IdentityFile ~/.ssh/github_work    IdentitiesOnly yes

[5] Check that the agent holds the key. "No agent" and "empty agent" print different messages.

console
$ ssh-add -lCould not open a connection to your authentication agent.$ eval "$(ssh-agent -s)"Agent pid 2772$ ssh-add -lThe agent has no identities.

If it is empty, load the key with ssh-add ~/.ssh/<key-file>. If an offered key is still refused, compare fingerprints: the SHA256:… from ssh-add -l -E sha256 must match a key under Settings → SSH and GPG keys on GitHub. With no key at all, create one with ssh-keygen -t ed25519 -C "user@example.com" and register the .pub contents.

[6] On networks that block port 22, test port 443. The host name changes to ssh.github.com. The first connection asks whether to trust the host key. **Before typing yes**, compare the fingerprint on screen with GitHub's published one — for Ed25519 it is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU. If it differs, answer no.

console
$ ssh -T -p 443 git@ssh.github.com; echo "exit=$?"The authenticity of host '[ssh.github.com]:443 ([…]:443)' can't be established.ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.This key is not known by any other names.Are you sure you want to continue connecting (yes/no/[fingerprint])? yesWarning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.git@ssh.github.com: Permission denied (publickey).exit=255

Getting Permission denied (publickey) here means 443 reaches the server and only the key is left to fix. If 443 works, add Hostname ssh.github.com and Port 443 under Host github.com, as the official guide shows.

If you typed yes without comparing, or the fingerprint looks wrong, list what was saved, remove just that host's entry, and connect again to compare:

console
$ ssh-keygen -lf ~/.ssh/known_hosts256 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU |1|nugbYmhGm+W3/cpmCpjXi8jCVV0=|fhz6rViCQ/TCwEgaqbuiH/2SaZA= (ED25519)$ ssh-keygen -R '[ssh.github.com]:443'# Host [ssh.github.com]:443 found: line 1/root/.ssh/known_hosts updated.Original contents retained as /root/.ssh/known_hosts.old

If ssh warns that the fingerprint changed, go to REMOTE HOST IDENTIFICATION HAS CHANGED. If you also see UNPROTECTED PRIVATE KEY FILE, fix that first.

Official sources: GitHub — Error: Permission denied (publickey) · Using SSH over the HTTPS port · GitHub's SSH key fingerprints

Analyze your auth.log (SSH) log in the browser ↗ — nothing is uploaded.

Check it with the ssh_config generator tool ↗ — calculated in your browser.

#git#github#ssh#ssh-agent