Knowledge

GitHub Permission denied (publickey)

#Git

When git clone, pull or push over SSH fails with this error, GitHub did not accept your SSH key. Usually the key is not generated, not added to your account, or not loaded into the agent.

Published by Mark van Eijk on June 23, 2026 · 1 minute read

  1. About the error
  2. Why do I see this error
  3. Solution
  4. Test the connection
  5. Generate a key if you don't have one
  6. Add the public key to GitHub
  7. Load the key into the agent
  8. Wrong remote protocol

About the error

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

You're connecting to GitHub over SSH, and GitHub rejected the authentication because none of the keys your client offered matches a key on your account.

Why do I see this error

  • You haven't generated an SSH key yet.
  • The public key isn't added to your GitHub account.
  • The key exists but isn't loaded into the SSH agent.
  • You're using an HTTPS-style setup but a remote that expects SSH (or vice versa).

Solution

Test the connection

GitHub has a dedicated endpoint for this. A success looks like a greeting, not a shell:

ssh -T git@github.com

If it says Hi <username>!, your key works and the problem is the repository remote, not auth. If it says Permission denied, continue below.

Generate a key if you don't have one

ssh-keygen -t ed25519 -C "you@example.com"

Press enter to accept the default location (~/.ssh/id_ed25519).

Add the public key to GitHub

Copy the public key (.pub) and paste it into GitHub under Settings → SSH and GPG keys → New SSH key:

cat ~/.ssh/id_ed25519.pub

Load the key into the agent

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Wrong remote protocol

If your account is set up for SSH but the repo was cloned over HTTPS (or the reverse), switch the remote URL:

git remote set-url origin git@github.com:you/repo.git

For the general server-side version of this error (your own servers rather than GitHub), see SSH Permission denied (publickey).

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

Removing tracked files in Git that should have been ignored

When git clone, pull or push over SSH fails with this error, GitHub did not accept your SSH key. Usually the key is not generated, not added to your account, or not loaded into the agent.

Read more →

Change casing of file or directory in Git

When git clone, pull or push over SSH fails with this error, GitHub did not accept your SSH key. Usually the key is not generated, not added to your account, or not loaded into the agent.

Read more →