"Permission denied (publickey)" on git push to GitHub: the fix
When you push over SSH, GitHub wants to see a key that is attached to your account. This error means your computer offered no key, or offered one GitHub does not know.
The error looks like this:
git@github.com: Permission denied (publickey).
How to fix it
- Don't use
sudowith Git. GitHub's guide says keys made withoutsudowill not be used bysudo git push. - Test the connection. Run
ssh -T git@github.com. Success prints a greeting with your username. Use the usergit, not your GitHub username, in the address. - Check a key is loaded. Run
eval "$(ssh-agent -s)"and thenssh-add -l -E sha256. If the list is empty, create an SSH key and add it to GitHub. - See what SSH offers. Run
ssh -vT git@github.com. A line with "Offering public key" means your key was found and sent. - Match it to your account. Compare the fingerprint with the keys under Settings, then SSH and GPG keys on GitHub. If yours is missing, add the public key.
- Or switch to HTTPS. If SSH is a hassle, change the remote to the HTTPS address with
git remote set-url origin <https-url>.
What you should see
ssh -T git@github.com greets you by username, and git push goes through.
Not fixed? Bring the exact message to Bilo and we will look at it with you.
Still stuck? Paste your error into BiloQuick questions
Which file do I upload to GitHub?
The public key (the file ending in .pub). Never share the private one.
It worked yesterday.
The key may no longer be loaded into the agent after a restart. Run ssh-add for it again.
I see a key on my account I don't recognise.
GitHub's guide says to delete it right away and contact GitHub Support.
Sources and date checked
- GitHub Docs: Error: Permission denied (publickey): https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey (checked 2026-11-01)
Written in our own words from the official pages above. Tool names are only references; we are not affiliated with them. Commands change between versions, so check the linked docs if something differs.