git / Guides

Git SSH Permission denied (publickey): what to check

This error means the SSH server rejected authentication. These examples target github.com; other providers and enterprise hosts can require different settings.

Examples use Bash; consult the references for details of your environment.

Check the remote and protocol

Run this inside the repository. An HTTPS remote uses HTTPS credentials, so an SSH-key fix will not change that connection. A GitHub SSH URL normally starts with git@github.com:.

git remote -v

For github.com the SSH user is git, not your account name. Verify the repository owner and name before changing a remote. Avoid switching protocols merely to hide the original problem.

Check the keys available to the agent

List the identities available to your current SSH agent. A message about no identities differs from an unavailable agent. Agent setup depends on your operating system and terminal.

ssh-add -l

If your existing key is not loaded, add its actual local filename, for example ssh-add ~/.ssh/id_ed25519. Register the matching public .pub key with the intended GitHub account. Keep the private key on your device; do not paste it into a website.

Test authentication to GitHub

Before accepting a new host key, compare its fingerprint with GitHub’s published SSH fingerprints, linked in the official connection guide below. Then run the test.

ssh -T git@github.com

A successful GitHub greeting names your account and says shell access is unavailable. That successful test normally exits with code 1. If authentication still fails, ssh -vT git@github.com shows which identities are offered. Running Git through sudo can select another user’s keys.

Separate authentication from repository access

After a successful SSH test, check that the repository can be read. This command lists remote references without changing local branches.

git ls-remote origin

An authenticated account still needs access to that repository. Check the remote spelling, organization membership and any required SSO authorization. Deploy keys may be limited to one repository. Follow the provider’s setup guide if no key exists; do not overwrite an existing key as a troubleshooting shortcut.

References

All guides