Unable to use git in WSL. C:\Windows\System32\OpenSSH\ssh.exe: not found
Asked Answered
L

3

7

So im on Windows 10 and a while ago i decided to use WSL so the I can get zsh. However, now I can no long use git from my wsl terminal, i.e I can no longer git pull from remote repo. When I try I get the following...

'C:\Windows\System32\OpenSSH\ssh.exe': 1: C:\Windows\System32\OpenSSH\ssh.exe: not found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Such operations work fine in bash and from GitHub Desktop. Why is WSL trying to use OpenSSH from Windows it should be Linux right?

Im struggling to find information on this problem so any help is greatly appreciated. Let me know if there is more information I can provide.

Lodovico answered 31/5, 2021 at 18:4 Comment(4)
What is the output of whereis ssh (in WSL)?Steenbok
I'm surprised WSL doesn't come with its own native ssh and git implementation. I haven't tried WSL yet, but if it's possible to install Git inside WSL that's what I would try.Freehanded
whereis ssh outputs ssh: /usr/bin/ssh /etc/ssh /mnt/c/WINDOWS/System32/OpenSSH/ssh.exe /usr/share/man/man1/ssh.1.gz And i have Git available inside WSL, but I can't pull from remote repo'sLodovico
Are you using 1password ssh agent?Elfland
H
15

I got the same error after changing the value "core.sshCommand" like this:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

In my file ~/.gitconfig, I disabled newlines like below :

#[core]
#       sshCommand = 'C:\\Windows\\System32\\OpenSSH\\ssh.exe'

Then when you are in a git repository, if you have the same problem check your my-project/.git/config file and if there is the new config disable it as above.

In my case it worked :-)
Have a nice day

Hedgerow answered 20/10, 2021 at 16:15 Comment(2)
The single quotes inside the double quotes was what i was lacking - Thnks yoU!Thallus
Simple "ssh.exe" works for me. git config --global core.sshCommand ssh.exeAmmamaria
T
2

As mmv_sat mentioned in the replies under ljr95's response, this issue was resolved for me by changing my git config for core.sshCommand from C:\Windows\System32\OpenSSH\ssh.exe to 'C:\Windows\System32\OpenSSH\ssh.exe'.

However, none of what I have done is related to utilizing git in WSL; this was all for my use of git and ssh in PowerShell on Windows to reach Bitbucket.

My Error

Cloning into 'repo_name'...
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.

If you are receiving an error like mine, the following resolution may help you.

View Your Config Values

You can view your own config by using:

git config --list

For me, that looked like:

...
core.sshcommand=C:\windows\System32\OpenSSH\ssh.exe

Resolution

Re-configure the git config core.sshCommand path to be wrapped in single quotes.

The command I ran to do that was:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

I was then able to clone my repo down as expected.

Thrill answered 13/5 at 20:24 Comment(0)
H
0

Double check if you have an environment variable GIT_SSH which would point to C:\Windows\System32\OpenSSH\ssh.exe: that would not be a valid path in a WSL session.

Unset it.
After that, it depends on the Windows 10 used ( 1709? 1809? 20H1? ...), and on the WSL used (WSL1 or WSL2?).

Hasin answered 1/6, 2021 at 7:42 Comment(2)
Windows 10 is 20H2 and i think i have WSL 1, how can i check?Lodovico
@JackLovett Type wsl -l -v, as described in askubuntu.com/a/1177730/5470Hasin

© 2022 - 2024 — McMap. All rights reserved.