Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2019 git problem: "Cannot spawn ... ssh.exe: No such file or directory" on fetch/push

Can't get VS2019 to fetch/push to the remote (happens to be on GitLab). What is the correct configuration?

  1. I'm using the built-in Windows 10 OpenSSH (C:\Windows\System32\OpenSSH)

  2. I've set env var GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe

  3. Private key loaded into running ssh-agent service via ssh-add.

  4. From a normal command window (i.e., not a WSL bash shell) I can push/fetch to my heart's delight.

  5. From VS2019, with the repo open (Git>Local Repositories>myrepo), when I try either Git>Fetch or Git>Push I get the following in the output window:

    Commit eebc0b4a created locally in repository r:\bbits\edu-bitcoin-staging
    Opening repositories:
    r:\bbits\edu-bitcoin-staging
    Pushing master
    Pushing to gitlab.com:bakins-bits/edu-bitcoin-staging.git
    Error: cannot spawn C:\Windows\System32\OpenSSH\ssh.exe: No such file or directory
    Error encountered while pushing to the remote repository: Git failed with a fatal error.
    Git failed with a fatal error.
    unable to fork
    
    Failed to push to the remote repository. See the Output window for more details.
    

Note the C:\Windows\System32\OpenSSH\ssh.exe: No such file or directory - and yet, that's the correct path:

C:\>dir C:\Windows\System32\OpenSSH\ssh.exe
 Volume in drive C is P70-MSVC
 Volume Serial Number is 8240-9525

 Directory of C:\Windows\System32\OpenSSH

10/15/2019  06:50 AM           882,688 ssh.exe
               1 File(s)        882,688 bytes
               0 Dir(s)  333,358,600,192 bytes free
like image 473
davidbak Avatar asked Nov 15 '22 22:11

davidbak


2 Answers

I think I've managed to resolve the issue here. Built-in Windows 10 OpenSSH is a 64-bit program. But the Git, that is running from within Visual Studio is 32-bit. Visual Studio uses the one in C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\bin" (adjust the path accordingly to your VS version).

The thing is, that Windows uses virtual folders to prevent 32-bit programs from accessing 64-bit libraries. So if 32-bit app tries to access System32 folder, it is being redirected to SysWOW64 instead. And there is no OpenSSH there. You can simulate that by trying to access OpenSSH folder from 32-bit powershell window:

> cd C:\Windows\System32\OpenSSH\

What you want to do is to set GIT_SSH to

C:\Windows\SysNative\OpenSSH\ssh.exe

SysNative is a virtual folder, it does not exist on your system physically. But by accessing it, program won't be redirected to SysWOW64

like image 122
51MARGL Avatar answered Dec 09 '22 14:12

51MARGL


Use this to escape space in "Program Files"

git config --global core.sshCommand 'C:\\PROGRA~1\\\\Git\\usr\\bin\\ssh.exe'
like image 25
Aleksei Loginov Avatar answered Dec 09 '22 14:12

Aleksei Loginov