Skip to main content
Download

git@github.com: Permission denied (publickey)

This error means GitHub rejected your SSH connection because it could not authenticate you with a key. Your code is safe. You just need to set up an SSH key once, and it takes five minutes.

Error explained

What this error means

When you use an SSH URL like git@github.com:team/project.git, Git authenticates with an SSH key pair instead of a password. GitHub checks whether your machine offers a private key matching a public key registered on your account. If no key matches, the connection is refused before Git can do anything.

Root causes

Why this happens

No SSH key on this machine

A fresh laptop or a new user account has no key pair in ~/.ssh. GitHub has nothing to match against, so every SSH connection is rejected.

Key not added to GitHub

You generated a key but never registered the public half on GitHub. The key exists locally, but GitHub does not know it belongs to your account.

Agent not offering the key

The key exists and is on GitHub, but the SSH agent is not loaded with it, or SSH offers another key first. Common after a reboot or on machines with several keys.

Step-by-step fix

How to fix it

Generate a key, add it to the agent and to GitHub, then test. You only do this once per machine.

Generate and load a key

Check for an existing key first. If there is none, create an Ed25519 key and add it to the agent.

Register on GitHub and test

Copy the public key to GitHub, then verify with ssh -T.

No SSH? Use HTTPS instead

If you cannot use SSH (locked-down network, shared machine), switch the remote to HTTPS and authenticate with a personal access token or credential manager.

Best practices

How to prevent it

One key per machine

Generate a dedicated key on each computer you use and register each one on GitHub. Never copy private keys between machines.

Test after any change

After an OS update, a reinstall, or a new key, run ssh -T git@github.com before you need to push something urgent.

Use a passphrase and the agent

Protect the private key with a passphrase and let the SSH agent (or your OS keychain) remember it. Security without retyping.

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about Permission denied (publickey)

Understand Git instead of memorizing fixes

GitQuest teaches you how Git and remotes really work through hands-on investigations, so errors like this one stop being mysterious.

Start practicing