THE GITHTML FIELD GUIDE

Fix GitHub SSH “Permission denied (publickey)” carefully

“Permission denied (publickey)” means the SSH server did not accept the available key authentication. Check the host, SSH username, loaded key, and the account associated with its public key. For github.com, use the git SSH user. Do not disable host-key verification, publish private keys, or run Git with elevated privileges as a routine fix.

Confirm the connection you are actually making

Inspect the remote URL and any SSH host alias it uses. A custom alias can select a different hostname or key than a plain github.com connection. On GitHub.com, the SSH login user is git rather than your personal username; the key establishes the account identity. Enterprise hosts can have different documented conventions, so follow the host’s official instructions.

A host-key warning is a different security issue from rejected user authentication. Verify the server fingerprint through official documentation before trusting a new or changed host key. Do not suppress the warning to get to the next error, because that removes protection against connecting to an impersonated server.

Check key availability without exposing it

List agent fingerprints and test authentication. The test’s greeting identifies the authenticated account if successful; GitHub does not provide an interactive shell, so the documented exit behavior differs from a normal shell login. If more detail is needed, use verbose SSH locally and redact paths and account information before sharing.

  1. Compare the offered public-key fingerprint with keys authorized on the intended account. Never upload or paste the private-key file as part of troubleshooting.
  2. If multiple accounts use different keys, inspect the relevant SSH configuration and select the intended identity explicitly according to your established setup.
shell
git remote -v
ssh-add -l -E sha256
ssh -T git@github.com

Verify repository authorization after authentication

A successful greeting for the wrong account is not a solution. Confirm the expected identity and then test repository read access. Organization requirements or repository-specific permissions can still prevent access after SSH authentication succeeds. Do not change commit author email to address those access failures; author metadata and transport identity are separate.

Avoid sudo as a routine remedy because it can select another user’s configuration and keys while creating ownership problems in the checkout. If a key is lost or revoked, follow a controlled replacement process and remove obsolete access only after verifying the new setup. Finish with a sanitized record of the actual cause so the same account-selection mistake does not recur.

  1. If ssh -T succeeds for github.com but the Git remote uses a custom host alias, test the alias actually named by the remote. Its SSH configuration may select another key. Comparing those two greetings can expose an account-selection mismatch without replacing any keys or repository history.
  2. If the agent lists no identities after a restart, check the approved key-loading procedure for your machine before generating a replacement keypair. The existing public key may still be correctly registered with GitHub. Reestablishing access to its matching private key can address the missing local agent state.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All fixing git problems guides →

Read as MarkdownAll guides

Fix GitHub SSH “Permission denied (publickey)” carefully · gitHtml