Skip to content

Instantly share code, notes, and snippets.

@bondarenkod
Last active September 22, 2025 07:18
Show Gist options
  • Save bondarenkod/20e96267a46f78bf98d3e999d04c102f to your computer and use it in GitHub Desktop.
Save bondarenkod/20e96267a46f78bf98d3e999d04c102f to your computer and use it in GitHub Desktop.
Git SSH: Permission denied (publickey). fatal: Could not read from remote repository.

If you encounter the following error on Windows: Permission denied (publickey). fatal: Could not read from remote repository. But at the same time, the command ssh -vvv [email protected] gives you this message: Hi USER_NAME! You've successfully authenticated, but GitHub does not provide shell access.

  • Option1: Add to your environment variables: GIT_SSH_COMMAND="C:/Windows/System32/OpenSSH/ssh.exe". Ensure there's no space after the equal sign. Also, verify that the path is correct for your OS. Note! I've expirinced some connection issues while trying to clone the repo via ssh:
git clone [email protected]:v3/company/project/reponame 
Cloning into 'reponame'... 
C:\Windows\System32\OpenSSH\ssh.exe: line 1: C:WindowsSystem32OpenSSHssh.exe: command not found fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

and remove the GIT_SSH_COMMAND from the env variables. Do logout.

  • Option2: change the Git configuration by running: git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
  • Don't forget to start the SSH agent service: Get-Service -Name ssh-agent | Set-Service -StartupType Manual Start-Service ssh-agent You can set the StartupType to Automatic if you want it to run when Windows starts.

A restart might be necessary, but in many cases, simply re-opening the terminal is sufficient.

Note: Git for Windows includes an embedded SSH client, which it might use by default. Switching to the Windows System32 SSH client can resolve certain authentication issues. image

@raulcanbereached
Copy link

I just found this article. Thank you, thank you, thank you @bondarenkod - This solved my issue!

@vitalykarasik
Copy link

Many thanks, I spent 2+ hours on this stupid issue, you made my day! :-)

@viallww
Copy link

viallww commented Apr 27, 2025

Thank you!

@bondarenkod
Copy link
Author

changed a few important details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment