Errorgit
Permission denied (publickey)
Why SSH git pushes fail with Permission denied (publickey), how to see which key is actually being offered, and how to add or load the right one.
Last updated
Errorgit
git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
What it means: The git server rejected your SSH connection because it couldn't authenticate any key you offered — either no usable key was sent, or the server doesn't have your public key on file for this account or repo.
Likely causes
Most probable first — with how to confirm.
- 1.No SSH key is loaded in your local agent, or the wrong one is being offered — run `ssh -T git@github.com` (or the equivalent for GitLab/Bitbucket) to see exactly which identity is being tried.
- 2.Your public key was never added to your account on the git host, or it was added to a different account than the one with access to this repo.
- 3.You're using the SSH remote URL (`git@github.com:...`) without SSH actually being set up — check `git remote -v`; the HTTPS URL sidesteps SSH entirely.
- 4.The key exists locally but has overly open file permissions, and SSH refuses to use a private key file that's group- or world-readable — check with `ls -l ~/.ssh/id_ed25519`.
Fixes
Safest first; destructive ones are called out.
- →Run `ssh -T git@github.com` to see which key gets offered and whether the host recognizes it — this diagnoses the problem without changing anything.
- →Add your public key (`~/.ssh/id_ed25519.pub` or `id_rsa.pub`) to the git host's SSH keys settings if it isn't there yet; generate one with `ssh-keygen -t ed25519` if you don't have one at all.
- →Start the SSH agent and load the key if it exists but isn't active: `eval "$(ssh-agent -s)"` then `ssh-add ~/.ssh/id_ed25519`.
- →As a quick workaround, switch the remote to HTTPS — `git remote set-url origin https://github.com/user/repo.git` — and authenticate with a token instead of SSH.