This error occurs when Git on Windows cannot communicate with remote repositories because Windows OpenSSH is misconfigured or conflicts with Git's bundled SSH client. The fix involves configuring Git to use the correct SSH executable or properly setting up Windows OpenSSH.
This error indicates that Git is attempting to use Windows OpenSSH for SSH connections to remote repositories, but the OpenSSH installation is not properly configured or is missing required components. Windows 10 and later include OpenSSH as an optional feature, but Git for Windows also bundles its own SSH client. When these two SSH implementations conflict or when Windows OpenSSH is partially installed, Git cannot establish SSH connections to remote hosts like GitHub, GitLab, or Bitbucket. The "fatal: Could not read from remote repository" portion confirms that Git was completely unable to access the remote repository because the SSH layer failed during connection setup.
First, determine which SSH executable Git is configured to use:
# Check Git's SSH command configuration
git config --get core.sshCommand
# Check the GIT_SSH environment variable
echo $env:GIT_SSH
# Find which ssh.exe is in your PATH
where.exe ssh
Get-Command ssh | Select-Object SourcePossible outputs:
- If core.sshCommand returns nothing, Git uses the default SSH
- Multiple ssh.exe paths indicate potential conflicts
- Common locations:
- C:\Windows\System32\OpenSSH\ssh.exe (Windows OpenSSH)
- C:\Program Files\Git\usr\bin\ssh.exe (Git for Windows bundled SSH)
Check if Windows OpenSSH is properly installed:
# Check installed OpenSSH components (run as Administrator)
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'Expected output for properly installed OpenSSH:
Name : OpenSSH.Client~~~~0.0.1.0
State : Installed
Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresent # Server is optionalIf OpenSSH.Client is not installed:
# Install OpenSSH Client (run as Administrator)
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0Verify the ssh.exe exists:
Test-Path "C:\Windows\System32\OpenSSH\ssh.exe"Windows OpenSSH requires the ssh-agent service to manage SSH keys:
# Check ssh-agent service status (run as Administrator)
Get-Service ssh-agent
# Set the service to start automatically
Set-Service -Name ssh-agent -StartupType Automatic
# Start the service
Start-Service ssh-agent
# Verify it's running
Get-Service ssh-agentExpected output after starting:
Status Name DisplayName
------ ---- -----------
Running ssh-agent OpenSSH Authentication AgentIf the service doesn't exist, Windows OpenSSH is not properly installed. Reinstall it using the steps above.
Add your SSH private key to the Windows ssh-agent:
# Add your default SSH key
ssh-add $env:USERPROFILE\.ssh\id_ed25519
# Or for RSA keys
ssh-add $env:USERPROFILE\.ssh\id_rsa
# List loaded keys
ssh-add -lIf you get "Could not open a connection to your authentication agent":
# Ensure ssh-agent is running first
Start-Service ssh-agent
# Then try adding the key again
ssh-add $env:USERPROFILE\.ssh\id_ed25519Verify the key location:
# Windows OpenSSH looks for keys here:
dir $env:USERPROFILE\.ssh
# Should contain:
# id_ed25519 (or id_rsa) - private key
# id_ed25519.pub (or id_rsa.pub) - public keyIf you want Git to use the Windows OpenSSH client:
# Set Git to use Windows OpenSSH
git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"
# Verify the setting
git config --get core.sshCommandTest the connection:
# Test SSH to GitHub
ssh -T [email protected]
# Expected successful response:
# Hi username! You've successfully authenticated, but GitHub does not provide shell access.Ensure PATH order is correct (Windows OpenSSH first):
# View current PATH
$env:PATH -split ';' | Select-String -Pattern "ssh|git" -CaseSensitive:$false
# Windows OpenSSH path should appear before Git paths
# C:\Windows\System32\OpenSSH should come before
# C:\Program Files\Git\usr\binIf Windows OpenSSH continues to cause issues, configure Git to use its bundled SSH client instead:
# Set Git to use its bundled SSH
git config --global core.sshCommand "C:/Program Files/Git/usr/bin/ssh.exe"
# Or remove the setting entirely to use Git's default
git config --global --unset core.sshCommand
# Also clear any GIT_SSH environment variable
[Environment]::SetEnvironmentVariable("GIT_SSH", $null, "User")Use Git Bash for SSH key management:
# In Git Bash, start the ssh-agent
eval $(ssh-agent -s)
# Add your SSH key
ssh-add ~/.ssh/id_ed25519
# Test the connection
ssh -T [email protected]This approach uses Git's bundled OpenSSH which is self-contained and doesn't depend on Windows OpenSSH configuration.
If you have multiple SSH executables, ensure the correct one takes precedence:
# Find all ssh.exe in PATH
where.exe ssh
# Typical output with conflicts:
# C:\Windows\System32\OpenSSH\ssh.exe
# C:\Program Files\Git\usr\bin\ssh.exeTo modify PATH order permanently:
1. Open System Properties: sysdm.cpl
2. Click "Environment Variables"
3. Under "System variables", select "Path" and click "Edit"
4. Move the desired SSH path higher in the list
For Windows OpenSSH priority:
- C:\Windows\System32\OpenSSH should be above
- C:\Program Files\Git\usr\bin
For Git SSH priority:
- Reverse the order, or remove Windows OpenSSH from PATH
Verify the change:
# Restart PowerShell, then:
where.exe ssh
# The first result will be usedAfter making changes, verify Git can connect to your remote:
# Test SSH connection to GitHub
ssh -T [email protected]
# Test SSH connection to GitLab
ssh -T [email protected]
# Verbose output for debugging
ssh -vT [email protected]Test Git operations:
# Clone a repository
git clone [email protected]:username/repository.git
# Or test with an existing repository
cd your-repo
git fetch origin
git pull origin mainIf still failing, check for detailed errors:
# Set GIT_SSH_COMMAND for verbose output
$env:GIT_SSH_COMMAND = "ssh -vvv"
git fetch origin### Understanding SSH Client Precedence on Windows
Git determines which SSH client to use in this order:
1. core.sshCommand Git configuration
2. GIT_SSH_COMMAND environment variable
3. GIT_SSH environment variable
4. First ssh.exe found in PATH
Check all of these:
git config --get core.sshCommand
echo $env:GIT_SSH_COMMAND
echo $env:GIT_SSH
where.exe ssh### Windows OpenSSH vs Git's SSH - Key Differences
| Aspect | Windows OpenSSH | Git's Bundled SSH |
|--------|----------------|-------------------|
| Location | C:\Windows\System32\OpenSSH | C:\Program Files\Git\usr\bin |
| Agent | Windows Service (ssh-agent) | Shell process (eval ssh-agent) |
| Key Location | %USERPROFILE%\.ssh | ~/.ssh (Git Bash) |
| Config | %USERPROFILE%\.ssh\config | ~/.ssh/config |
### Key Storage Differences
Windows OpenSSH and Git's SSH may look for keys in different locations:
# Windows OpenSSH default key locations:
# C:\Users\YourName\.ssh\id_ed25519
# C:\Users\YourName\.ssh\id_rsa
# Git Bash interprets ~ as:
# /c/Users/YourName/.ssh/id_ed25519
# Which is the same physical location### Troubleshooting ssh-agent Service Issues
If the ssh-agent service won't start:
# Check for errors in Event Viewer
Get-EventLog -LogName System -Source Service* -Newest 20 |
Where-Object { $_.Message -like "*ssh*" }
# Repair OpenSSH installation
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Restart the computer after reinstalling### Using SSH Config File with Windows OpenSSH
Create or edit %USERPROFILE%\.ssh\config:
Host github.com
HostName github.com
User git
IdentityFile C:/Users/YourName/.ssh/id_ed25519
IdentitiesOnly yes
Host gitlab.com
HostName gitlab.com
User git
IdentityFile C:/Users/YourName/.ssh/gitlab_key
IdentitiesOnly yesImportant: Use forward slashes in paths, even on Windows.
### Corporate/Enterprise Environments
Group Policy may restrict OpenSSH:
# Check if OpenSSH is blocked by policy
Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OpenSSH" -ErrorAction SilentlyContinue
# Check Windows Defender Firewall
Get-NetFirewallRule -DisplayName "*SSH*" | Select-Object DisplayName, Enabled, ActionIf blocked, use Git's bundled SSH or contact your IT department.
### WSL (Windows Subsystem for Linux) Considerations
If using WSL alongside Windows:
# In WSL, use Linux SSH, not Windows
which ssh
# Should return: /usr/bin/ssh
# Don't mix Windows and WSL SSH configurations
# Keep separate keys or use ssh-agent forwarding### Debugging with Verbose Output
For detailed connection information:
# Maximum verbosity
ssh -vvv [email protected]
# Key things to look for:
# - "Trying private key: ..." - shows which keys are being tried
# - "Authentications that can continue: publickey" - server expects key auth
# - "Authentication succeeded" - successful connection### Resetting to Clean State
If configuration is too tangled:
# Remove Git SSH settings
git config --global --unset core.sshCommand
git config --global --unset-all core.sshCommand
# Clear environment variables
[Environment]::SetEnvironmentVariable("GIT_SSH", $null, "User")
[Environment]::SetEnvironmentVariable("GIT_SSH_COMMAND", $null, "User")
# Restart terminal and test
git clone [email protected]:octocat/Hello-World.gitkex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git