World map

 

BM: Baca dalam Bahasa Melayu

World 11: Rescue Center

Permission denied (publickey)

You will learn: two calm fixes when GitHub says Permission denied (publickey).

The problem

git push answers: git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Terminal output: $ git push 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.

You type git push. GitHub says Permission denied. Your work is safe! GitHub just can’t tell who you are. This happens to everyone.

Watch

bash
ssh -T git@github.com
git@github.com: Permission denied (publickey).
ssh -T git@github.com answers: git@github.com: Permission denied (publickey).

Your computer proves who you are with an SSH key. Test the key alone with ssh -T git@github.com. Same answer: GitHub doesn’t know this key.

Try it

What’s the most likely cause?

Pick one answer.

Try it

Put the SSH fix in order, first step at the top.

First step at the top. Put these in order. Use the arrows, or drag.

  • ssh-add -l: is a key loaded?
  • Add the public key (.pub) to your GitHub account
  • ssh-add ~/.ssh/id_ed25519: load your key
  • ssh -T git@github.com: test again

Watch

bash
ssh -T git@github.com
Hi you! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T git@github.com answers: Hi you! You've successfully authenticated, but GitHub does not provide shell access.

When it works, GitHub greets you by name. “No shell access” is normal. Now git push works too.

Try it

In a hurry? Switch origin to the HTTPS address. Then push again.

6d3a9b1a8feb63270a76ebcf4670

Predict

On a real computer, HTTPS asks you to sign in. What works as the password?

Pick one answer.

You did it!

You can now fix Permission denied (publickey), two ways.

Go deeper (optional)

No key yet? Make one with ssh-keygen -t ed25519 -C "you@example.com" (World 4). Only the .pub file goes to GitHub. Never share the private key. Using sudo git push? Drop the sudo. Your keys belong to you, not to the admin account.