lochana.Back to portfolio
Git

Fix "Permission denied (publickey)" when pushing to GitHub

SSH only offers keys it can find. Run ssh -vT git@github.com to see which keys it tried, then point it at yours with IdentityFile in ~/.ssh/config.

  • Beginner
  • ~7 min
  • 5 steps
  • Runs in your browser

What you’ll practise

0/4
  • Find out which keys SSH tried.
  • Rule out the server side: GitHub has the key.
  • Make SSH offer the right key.
  • Predict which account a key logs you in as.

Before you start

  • You’ve used git push
  • An SSH remote looks like git@github.com:owner/repo.git
HANDS-ON WORKSPACE

Simulated Git

Guided mode
STEP 01 / 05

See the push fail.

Your goal: push Maya’s branch from her new laptop. Her key is already on GitHub. In Terminal, run git push.

Step 1 of 5 · Reproduce the error SIMULATION
maya@work-laptopacme/web · feature/profile
Not pushed yet
Choose a command below to run it.

Run

Learn at your own pace.

TAKE IT INTO THE REAL WORLD

How this works in real projects

The ideas behind this lesson, with the official documentation to read next.

01

SSH offers only the keys it finds

SSH tries default key names such as id_ed25519, keys loaded in ssh-agent, and keys named by IdentityFile. A key called anything else, such as github_work, is never offered, even if GitHub has it.

OpenSSH: ssh_config IdentityFileman.openbsd.org
03

Point SSH at the key, then check the account

Add Host github.com and IdentityFile ~/.ssh/<key> to ~/.ssh/config. Then ssh -T git@github.com names the account the key logs you in as.

KEEP PRACTISING

Try another lesson

All lessons
Docker DesktopBeginner

Containers & Docker

Fix an app container that can't reach its database

Your app container restarts with ECONNREFUSED 127.0.0.1:5432 while Postgres runs. Inside a container, localhost is that container: connect to the db service on 5432.

~7 minStart lesson