Learn / Git

Fix "Permission denied (publickey)" on GitHub

GitHub could not match an SSH key on your computer to your account. Your repo and your work are fine. Find the one missing piece, fix it, and test.

The error

You run git push, git pull or git clone and see this:

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.

The first line comes from SSH. The last three come from Git, which only knows the connection failed.

A few words first

  • SSH is a secure way for your computer to talk to another computer. Git uses it when your repo address starts with git@github.com:.
  • An SSH key is a pair of files. The private key (for example id_ed25519) stays on your laptop and is never shared. The public key (the same name ending in .pub) goes to GitHub.
  • The SSH agent is a small helper program that holds your keys in memory and offers them when you connect.

“Permission denied (publickey)” means your computer offered no key, or offered a key GitHub has never seen. It is a sign-in problem, not a problem with your code.

Check first (these commands change nothing)

git remote -v          # does the address start with git@github.com: ?
ls ~/.ssh              # is there a key, like id_ed25519 and id_ed25519.pub?
ssh-add -l -E sha256   # which keys is the agent offering?
ssh -T git@github.com  # test the key with GitHub

If the agent has no keys, ssh-add -l -E sha256 prints The agent has no identities. If it has one, you see a line with its fingerprint (a short code that identifies the key):

256 SHA256:... you@example.com (ED25519)

Find your cause

You findFix
No key files in ~/.sshCreate a key and add it to GitHub (next section).
Key files exist, but the agent has no identitiesRun eval "$(ssh-agent -s)", then ssh-add ~/.ssh/id_ed25519.
The agent has a key, but GitHub still says noOpen GitHub, Settings > SSH and GPG keys, and compare the fingerprints. Add the missing one.
You ran sudo git pushDrop sudo. It runs as another user, who has none of your keys.
The address is yourname@github.com:...Always connect as the user git: git@github.com:....
A company account with single sign-on (SSO)Next to the key on GitHub, click Configure SSO, then Authorize.

The fix: add a key to GitHub

This is the most common case: a new laptop, or a key that was never added.

ssh-keygen -t ed25519 -C "you@example.com"  # Enter for the default file, then a passphrase
cat ~/.ssh/id_ed25519.pub                   # print the PUBLIC key and copy it
# GitHub: Settings > SSH and GPG keys > New SSH key > paste
ssh -T git@github.com                       # test again

A passphrase is a password for the private key, in case the laptop is stolen. When the test works, GitHub replies:

Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

The first time, SSH asks if you trust github.com and shows a fingerprint. Compare it with GitHub's published fingerprints, then type yes. It only asks once. Now run your git push again.

Only share the file ending in .pub. Anyone with your private key can push as you. Never paste it into GitHub, a chat or a ticket.

No time? Switch to HTTPS

HTTPS is the other way to connect, and it works on networks that block SSH. Change the repo's address, then let the GitHub CLI (gh) handle the sign-in:

git remote set-url origin https://github.com/you/shop-app.git
git remote -v      # check the new address
gh auth login      # choose GitHub.com, HTTPS, log in with browser
gh auth setup-git  # Git now asks gh for your login

GitHub does not accept your account password for Git. Use SSH, a gh login or a personal access token.

Related errors

If GitHub knows who you are but still says no, you get Permission to OWNER/REPO.git denied to USER or a 403 instead. That means the wrong account, or an account without write access. If the push reaches GitHub and is rejected (fetch first), read Fix “git push rejected (fetch first)”. Studying for the GitHub Foundations exam? See the GH-900 study plan.

GitHub steps and messages checked on docs.github.com on 17 November 2026. The Git and ssh-add output above was reproduced in a test repo.

From the book

Git / GitHub Study Guide

151 pages for beginners: every command explained, 4 local drills with a PASS or FAIL checker, 4 GitHub labs written as work tickets and GH-900 exam prep.