Error Codes Wiki

Git Permission Denied (Publickey) — SSH Authentication Failure on Windows

Warningapplication

Overview

Fix Git 'Permission denied (publickey)' error on Windows when SSH key authentication fails for GitHub, GitLab, or Bitbucket repositories.

Key Details

  • This error occurs when Git cannot authenticate with the remote server using SSH keys
  • Windows has multiple SSH agents: OpenSSH (built-in), Git for Windows SSH, and PuTTY (Pageant)
  • SSH keys must be added to both the local SSH agent and the remote service (GitHub/GitLab/Bitbucket)
  • Windows OpenSSH stores keys in %USERPROFILE%\.ssh\ directory
  • The wrong SSH client or agent being used is a common Windows-specific issue

Common Causes

  • SSH key not added to the GitHub/GitLab/Bitbucket account settings
  • SSH agent not running or key not loaded into the agent
  • Git using a different SSH client than where the keys are configured
  • SSH key passphrase not entered or cached, causing silent authentication failure

Steps

  1. 1Test SSH connection: 'ssh -T git@github.com' — should show your username if working
  2. 2Generate SSH key if none exists: 'ssh-keygen -t ed25519 -C "your@email.com"'
  3. 3Start SSH agent: open PowerShell as admin > 'Get-Service ssh-agent | Set-Service -StartupType Automatic' > 'Start-Service ssh-agent'
  4. 4Add key to agent: 'ssh-add %USERPROFILE%\.ssh\id_ed25519'
  5. 5Add the public key to GitHub: copy output of 'type %USERPROFILE%\.ssh\id_ed25519.pub' > GitHub > Settings > SSH and GPG keys > New SSH key

Tags

gitsshpublickeyauthenticationgithub

Related Items

More in Application

Frequently Asked Questions

SSH is more convenient once set up — no password prompts. HTTPS works immediately but requires a credential manager for password caching. GitHub recommends SSH with ed25519 keys.