git@github.com: Permission denied (publickey)
GitHub rejected the SSH connection because no uploaded SSH key matched a key offered by your computer.
What does this error mean?
Git reached GitHub over SSH, but GitHub could not associate any key offered by your SSH client with an account that can access the repository.
Why does this happen?
- No SSH key exists on this computer.
- The SSH key exists but is not loaded into the SSH agent.
- The public key has not been added to the correct GitHub account.
- The remote points to a GitHub account or organization you cannot access.
- An SSH config rule is offering the wrong key for github.com.
AI explanation
The repository is not rejecting your Git command itself. The connection fails one layer earlier, during SSH identity verification. First confirm which remote host Git uses, then inspect which keys the SSH client offers, and finally verify that the matching public key belongs to a GitHub account with repository access.
Quick fix
ssh -T git@github.com ssh-add -l git remote -v
Step-by-step fix
ssh-add ~/.ssh/id_ed25519 ssh -T git@github.com
ssh-keygen -t ed25519 -C "your-email@example.com" cat ~/.ssh/id_ed25519.pub
git remote -v git remote set-url origin git@github.com:OWNER/REPOSITORY.git
Alternative solutions
Windows PowerShell
Get-Service ssh-agent | Set-Service -StartupType Automatic Start-Service ssh-agent ssh-add $env:USERPROFILE\.ssh\id_ed25519
Run PowerShell as Administrator only when changing the ssh-agent service startup type.
macOS / Linux
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
Use the actual private-key filename when it differs from id_ed25519.
HTTPS remote
git remote set-url origin https://github.com/OWNER/REPOSITORY.git git remote -v
HTTPS uses a credential manager or personal access token instead of an SSH key.
Multiple GitHub accounts
ssh -G github.com | grep identityfile ssh -vT git@github.com
Use host aliases in ~/.ssh/config when work and personal accounts require different keys.
Real example
origin git@github.com:wrong-account/private-repo.git (fetch) origin git@github.com:wrong-account/private-repo.git (push)
origin git@github.com:correct-account/private-repo.git (fetch) origin git@github.com:correct-account/private-repo.git (push)
Frequently asked questions
Authentication proves who you are. You still need write permission to that repository and branch, and an organization may require SSO authorization for the key.