People constantly search for Permission denied (publickey). This guide walks through a clean SSH key setup for GitHub (and the same key often works for Linux servers).

1. Generate a key (prefer Ed25519)

ssh-keygen -t ed25519 -C "you@example.com" -f ~/.ssh/id_ed25519

Press Enter for no passphrase (convenient) or set one (more secure). Avoid copying private keys to chat or email.

2. Start agent and add the key

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

3. Copy the public key

cat ~/.ssh/id_ed25519.pub

Paste into GitHub: Settings → SSH and GPG keys → New SSH key.

4. Test GitHub

ssh -T git@github.com

Expect a greeting mentioning your username. If it hangs or fails, see below.

5. Common fixes

  • Wrong remote URL. Use SSH form: git@github.com:ORG/REPO.git (not HTTPS if you rely on SSH).
  • Multiple keys. Use ~/.ssh/config with Host github.com and IdentityFile ~/.ssh/id_ed25519.
  • File permissions. chmod 700 ~/.ssh and chmod 600 ~/.ssh/id_ed25519.