GitHub Permission Denied (publickey) Error

Share
Ongoing macOS, Windows, Linux Updated November 13, 2026Based on 6 user reportsHow we research

Quick answer

GitHub rejects the SSH connection because it cannot match a private key on your machine to a public key on your account. Load the right key into ssh-agent, make sure its public half is under Settings > SSH and GPG keys, and connect as the git user.

Most likely fix: Test the connection and read the verbose output

How to fix it

Try these in order — the most common fix is first.

  1. 1. Test the connection and read the verbose output

    1. Run ssh -vT git@github.com
    2. Confirm it connects to github.com on port 22 and see which keys SSH offers
    3. A success message reads 'Hi USERNAME! You've successfully authenticated'
    Did this fix it?
  2. 2. Load your key into the SSH agent

    1. Run eval "$(ssh-agent -s)"
    2. Run ssh-add -l -E sha256 to list loaded keys
    3. If the list is empty, run ssh-add ~/.ssh/YOUR_KEY (or generate a new key with ssh-keygen -t ed25519)
    4. To test one specific key without the agent: ssh -i ~/.ssh/KEY-FILE -vT git@github.com
    Did this fix it?
  3. 3. Make sure GitHub has the matching public key

    1. Open GitHub > Settings > SSH and GPG keys
    2. Compare the fingerprint from ssh-add -l -E sha256 with the keys listed
    3. If yours is missing, click New SSH key and paste the contents of the .pub file
    4. Delete any key you do not recognise and contact GitHub Support
    Did this fix it?
  4. 4. Use the git user in the remote URL

    1. Run git remote -v
    2. If the URL is ssh://YOURNAME@github.com/..., change it: git remote set-url origin git@github.com:OWNER/REPO.git
    3. Retest with ssh -T git@github.com
    Did this fix it?
  5. 5. Stop using sudo with git

    1. Keys generated without sudo are not used by sudo git
    2. Either run every git command without sudo or generate and register keys for the root user
    Did this fix it?
  6. 6. Fall back to SSH over port 443 on restricted networks

    1. Edit ~/.ssh/config and add Host github.com with HostName ssh.github.com, Port 443, User git
    2. Retest with ssh -T git@github.com
    Did this fix it?

Symptoms

git clone, pull or push over SSH ends with 'git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.'

Why it happens

  • No private key is loaded in ssh-agent
  • The public key was never added to your GitHub account (or was removed)
  • The key has a custom file name that SSH does not try by default
  • The remote URL uses your GitHub username instead of the git user
  • Git was run with sudo, so it looks in root's keys
  • Connecting to the wrong host or port

This guide also covers

  • permission denied publickey github
  • git@github.com permission denied (publickey)
  • fatal could not read from remote repository github
  • github ssh key not working

Still not working?

If GitHub keeps failing, you're not alone. See every GitHub problem users report or the alternatives people switch to.

Need a custom web app or internal tool? Our small team builds it, on your domain or hosted by us. Price agreed together.

Get a quote
Fixed it? Share this guide

Other GitHub errors

All 11 GitHub errors and fixes →