FIX · ERROR

"Permission denied
(publickey)."

GitHub closed the SSH connection because none of the keys your computer offered match a key on your account. The error is about the key, not your password.

ssh -T git@github.comssh-add -lssh -vTSSH and GPG keys

The short answer

check three things
1

The user

Always connect as git, never your username. Remote URLs look like git@github.com:you/repo.git.

2

The key

ssh-add -l lists loaded keys. Nothing listed? Generate a key, or load it with ssh-add.

3

The account

Compare the fingerprint with Settings, then SSH and GPG keys on GitHub. Add the public key if missing.

Only ever share the public key (the .pub file). The private key stays on your computer.

What it looks like

message from GitHub Docs

The first command shows the common mistake: connecting as your username. The messages are as shown in the GitHub Docs page for this error. The success line is the usual reply to ssh -T git@github.com.

Pick the fix that fits

what you want
you want to
run
result
Wrong user in the URL
git remote set-url origin git@github.com:OWNER/REPOSITORY.git
Every SSH connection to GitHub is made as the git user.
No key loaded
ssh-add -l, then ssh-add ~/.ssh/id_ed25519 if it lists nothing
Use your own key file name. Start the agent first if needed. GitHub Docs shows eval "$(ssh-agent -s)".
Key not on GitHub
Copy the .pub file into GitHub, Settings, SSH and GPG keys, New SSH key
Compare the fingerprint from ssh-add -l -E sha256 with the list on GitHub.
Used sudo with git
Run the same command again without sudo
sudo uses root's keys, not yours. GitHub says not to use sudo with Git.

Check it worked

always

Run ssh -T git@github.com. You should see "Hi USERNAME! You've successfully authenticated". For detail, run ssh -vT git@github.com and read the "identity file" and "Offering public key" lines: "Trying private key" with no offer means no key file was found. Then try your git push or git clone again. Chapter 15 walks through setup step by step.

When it goes wrong

related messages
fatal: Could not read from remote repository.Usually follows this errorFix the key problem above, and check the remote URL with git remote -v.
fatal: Authentication failedThat is HTTPS, not SSHSee the authentication fix.

Questions people ask

What does Permission denied (publickey) mean?

GitHub rejected your SSH connection because none of the keys offered match a key on your account.

Why must I use the git user?

GitHub identifies you by your key, not by a username. All SSH connections must be made as git, such as git@github.com.

How do I see which keys my computer offers?

Run ssh-add -l to list loaded keys, or ssh -vT git@github.com for detailed connection output.

Should I share my private key?

Never. Add only the public key (.pub) to GitHub. The private key stays on your computer.

Git, Visually · Parts 1 to 3 · English