Error Codes Wiki

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

Warningapplication

About Git Permission Denied (Publickey)

Fix Git 'Permission denied (publickey)' error on Windows when SSH key authentication fails for GitHub, GitLab, or Bitbucket repositories. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Test SSH connection: 'ssh -T git@github.com' — should show your username if working. Generate SSH key if none exists: 'ssh-keygen -t ed25519 -C "your@email.com"'. Start SSH agent: open PowerShell as admin > 'Get-Service ssh-agent | Set-Service -StartupType Automatic' > 'Start-Service ssh-agent'. Add key to agent: 'ssh-add %USERPROFILE%\.ssh\id_ed25519'. Add the public key to GitHub: copy output of 'type %USERPROFILE%\.ssh\id_ed25519.pub' > GitHub > Settings > SSH and GPG keys > New SSH key. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our Windows Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

Should I use SSH or HTTPS for Git?

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.

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.