30

I am having a hard time getting Github (+Netbeans to work).

I want to use ssh with git (on Windows 7) to, e.g., commit or clone a project, but I keep getting this error message :

$ git clone git@github.com:USER/PROJECTNAME.git
error: cannot spawn C:\Program Files (x86)\Git\bin\ssh.exe: No such file or directory
fatal: unable to fork

Note: For now, my GIT_SSH environment variable is pointing to C:\Program Files (x86)\Git\bin\ssh.exe, but I have also tried C:\Program Files (x86)\Git\bin, erasing it entirely, pointing to putty's/plink's folder, and pointing to their executables, but still the same message.

When I test the connection everything works fine:

$ ssh -T git@github.com
Hi USER! You've successfully authenticated, but GitHub does not provide shell access.

What am I doing wrong? Does it make a difference if I do the git init in the directory in the first place?

EDIT:

This didn't help:

setting GIT_SSH to plink.exe and adding plink's path to PATH

**EDIT 2 **

result of command with GIT_TRACE=2

$ GIT_TRACE=2 git clone git@github.com:XXX/AffableBean
trace: built-in: git 'clone' 'git@github.com:XXX/AffableBean'
Cloning into 'AffableBean'...
trace: run_command: 'Plink.exe' '-batch' 'git@github.com' 'git-upload-pack '\''XXX/AffableBean'\'''
error: cannot spawn Plink.exe: No such file or directory
fatal: unable to fork
Patryk
  • 22,602
  • 44
  • 128
  • 244
  • Does GIT_SSH have the spaces escaped at all? In your second example it looks like you can run ssh directly, so is that in your path? I'd guess if you have ssh in your PATH you shouldn't need the GIT_SSH variable to be set. – Stephen Newell May 13 '12 at 19:28
  • @StephenNewell Even if I have `ssh` (or any other ssh client in the PATH) I still get the same message. I have even tried unsetting `GIT_SSH` variable but it still won't work. – Patryk May 13 '12 at 19:42
  • What error message to you get if GIT_SSH is unset? It looks like ssh is working correctly by itself, but git isn't playing nicely for whatever reason. – Stephen Newell May 13 '12 at 19:47
  • @StephenNewell Each time I get the message e.g. : `error: cannot spawn C:\Putty\plink.exe: No such file or directory fatal: unable to fork` but when `GIT_SSH` is unset then e.g. `...plink.exe` changes to `ssh` – Patryk May 13 '12 at 19:53
  • Was I correct that the folder containing `ssh` is in `PATH`? – Stephen Newell May 13 '12 at 19:57
  • @StephenNewell Yes it is but I have already tried many combinations with this and still no go. I have found out that when I use ssh from `cmd` then I get error about lack of library `msys-crypto-0.9.8.dll`. But it's still not important since I have tried using `plink.exe` as well. – Patryk May 13 '12 at 20:00
  • How did you get ssh to work originally? Was that through `plink`? – Stephen Newell May 13 '12 at 20:27
  • @StephenNewell What do you mean - how I got ssh to work originally? In the Git bash? To test it I normally type e.g. `ssh -T git@github.com` and it works(the test). – Patryk May 14 '12 at 04:32

13 Answers13

16

None of the answers so far worked for me. What ended up fixing this issue for me was removing quotes from my GIT_SSH variable and don't escape any characters at all, no MSYS path style (eg. /c/path\ to\ putty/plink.exe). Just enter the path normally, Git handles the quoting.

set GIT_SSH=C:\path to putty\plink.exe

That's it. When using GIT_TRACE you can see that the variable gets quoted in the resulting command so:

  1. the added double quotes change the string passed to the command and

  2. the path is wrapped in single quotes so the spaces are ok.

Hope that helps someone.

th3coop
  • 411
  • 4
  • 11
  • 4
    IMPORTANT: Please note that this is NOT CORRECT if you are explicitly trying to use Windows' internal, native, OpenSSH feature (available since Windows 10 1803). In that case, the correct reference would be: C:\Windows\SysNative\OpenSSH\ssh.exe Further, if you are trying to integrate things with Visual Studio 2022, the correct way to specify this in your %UserProfile%/.gitconfig, is STRICTLY, EXACTLY, AND PRECISELY this: [core] sshcommand = '"C:\\Windows\\SysNative\\OpenSSH\\ssh.exe"' Note the single quotes SURROUNDING the double-quotes, and "SysNative". – breakpoint Feb 19 '22 at 09:10
  • @breakpoint can you please explain why this unconventional path? Give a pointer to some documentation? I say unconventional since it differs from where the actual ssh.exe file is – Dariopnc May 03 '22 at 14:02
11

In my case setting GIT_SSH to:

GIT_SSH=/c/Program\ Files\ (x86)/Git/bin/ssh.exe

worked in git bash.

Edit: This should not be required any more. Instead use the Windows credential manager. Thanks @breakpoint

schoetbi
  • 12,009
  • 10
  • 54
  • 72
  • Thanks. This worked for me with a small modification. I was using Git Bash on windows. GIT_SSH=/c/Program\ Files\ \\(x86\\)/Git/bin/ssh.exe . Needed backslashes before the brackets also. – jay Feb 10 '15 at 18:36
  • This worked for me too. Running Git Bash on Windows 10 with the error message error: cannot spawn c:\Program Files (x86)\GitExtensions\PuTTY\: No such file or directory fatal: unable to fork – Dan Persson May 14 '16 at 06:58
  • @DanPersson of course it's no such file or directory, because the first space will broke the whole path, in these case you need to use the \ before every space, or just simply use GIT_SSH="c:\Program Files (x86)\Git\bin\ssh.exe" and that's all. – golddragon007 Sep 17 '18 at 14:02
  • What a joke this space between Program and Files in Windows. 20+ years I've heard about it. – Fabien Haddadi Sep 16 '21 at 10:06
  • 1
    Again, this is NO LONGER CORRECT For Windows 10 build 1803 or later. I know I'm leaving a lot of comments in here, but you all know what it's like coming across stale documentation years later and trying to apply it. Windows now NATIVELY SUPPLIES OpenSSL, and you will want to use it. For one thing, it's the only clean way to tie into the Credential Manager (you should NOT be running ssh-agent manually; it's a service now, just set it to start automatically). See my comments above. – breakpoint Feb 19 '22 at 09:17
6

Have you tried installing ssh.exe to a path that does not contain spaces? And have you tested whether quoting backslashes works (\\)?

You could also try GIT_TRACE=2 git clone <...>, it should show you the command and parameters git is trying to run for connecting.

user1338062
  • 11,939
  • 3
  • 73
  • 67
  • What do you mean by 'installing ssh.exe' ? Which ssh so you mean here? OpenSSH ? Git's ssh ? – Patryk May 19 '12 at 19:44
  • I meant `Git\bin\ssh.exe` which is mentioned in the error message. To me it looks like there's a problem with the quotation of the path, so making sure the ssh.exe is installed in a path without spaces might help. – user1338062 May 20 '12 at 07:09
  • Where should I test quoting backslashes ? In the PATH ? If not then were ? – Patryk May 23 '12 at 10:30
  • I would test installing git's ssh.exe to a path without spaces first (eg. "c:\git")! See this comment: https://code.google.com/p/msysgit/issues/detail?id=313#c3 – user1338062 May 25 '12 at 09:18
  • I have already tried that: I have copied `ssh.exe` to `C:\Putty` and set my `GIT_SSH` to `C:\Putty\ssh.exe` and still : I get this : [http://pastebin.com/fXBvT3X8](http://pastebin.com/fXBvT3X8) P.S. I have also tried `C:\\Putty\\ssh.exe` – Patryk May 25 '12 at 15:57
  • Nothing to do with spaces in my case. See my reply further down. It was because `OpenSSH/ssh.exe` took precedence in `%PATH%` ! – Fabien Haddadi Sep 16 '21 at 10:45
5

In my case, I was able to resolve that issue by creating a directory junction in CMD terminal and resetting GIT_SSH.

Find the path of ssh command by running this Windows CMD command in the Git Bash terminal.

$ where ssh
C:\Program Files\Git\usr\bin\ssh.exe

Create a junction without white-spaces for the original Git directory in CMD terminal.

mklink /J \git "\Program Files\Git"

Then edit GIT_SSH environmental variable to use the junction. In case of Windows 7, Control Panel > System and Security > System > Advanced system settings.

C:\git\usr\bin\ssh.exe

I encountered this issue somehow after switching PuTTY usage to OpenSSH. The git version was 2.21.0.windows.1. I hope this helps.

yoshy27
  • 111
  • 2
  • 5
  • If you are receiving this message in the console of PHPStorm IDE, this may not be enough. I may fail further down the track, with references to Linux-based systems, such as "`/home/ – Fabien Haddadi Sep 07 '21 at 09:14
  • IMPORTANT: Please note that this is NOT CORRECT if you are explicitly trying to use Windows' internal, native, OpenSSH feature (available since Windows 10 1803). In that case, the correct reference would be: C:\Windows\SysNative\OpenSSH\ssh.exe Further, if you are trying to integrate things with Visual Studio 2022, the correct way to specify this in your %UserProfile%/.gitconfig, is STRICTLY, EXACTLY, AND PRECISELY this: [core] sshcommand = '"C:\\Windows\\SysNative\\OpenSSH\\ssh.exe"' Note the single quotes SURROUNDING the double-quotes, and "SysNative". – breakpoint Feb 19 '22 at 09:08
4

What an epic trek! Nothing above worked for me, but here is my solution. Before that operation, I always got:

error cannot spaw ssh: permission denied.

Pre-req: Git for Windows, installed in e.g. C:\Program Files\Git

  • Windows key
  • type in "env" + Enter
  • [Environment Variables] button, System variables section
  • Edit or add GIT_SSH=ssh
  • while you're in that dialog, now edit Path, same section
  • add value C:\Program Files\Git\usr\bin, or wherever your Git ssh.exe binary sits.
  • I insist on your git ssh.exe binary, NOT your OpenSSH one, which ships with Windows 10 these days, in %SYSTEMROOT%\System32\OpenSSH\
  • Now is the crucial step: use Move up to give the Git ssh.exe precedence over OpenSSH. (see picture below)
  • OK out everything, and reload your working console

git push should now work. enter image description here

Note that:

  • no symlink or junction was needed
  • no change to any Windows permissions
  • no escaping of any space or anything
  • no use of double quotes
Fabien Haddadi
  • 1,814
  • 17
  • 22
2

Unless you have some obscure anti-virus interaction, the only other case (beside issue 313 you are referring to) where this error message is seen is:

"error: cannot spawn git: No such file or directory"

if you ever get this error "error: cannot spawn git: No such file or directory" its a really nasty issue.
It took me a day to track it down, but it boils down to if you have more then 500 tags in a repository it must blow up some internal command line limits.
TLDR: if you get this error, remove a bunch of your tags.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks for the answer but what are these tags ? – Patryk May 18 '12 at 08:51
  • @Patryk my point was for you to check if your GitHub repo you attempting to clone has too much tags already declared in it: see ,for instance, the tags of this repo: https://github.com/git/git/tags, and check if the repo you want to clone has more than 500 tags: `https://github.com/username/reponame/tags` – VonC May 18 '12 at 10:01
  • No this is not the issue cuz the repo I want to clone is almost empty - there's just a README file and one file with code. – Patryk May 18 '12 at 10:41
  • @Patryk ok, I will leave the answer in case others have that issue. – VonC May 18 '12 at 11:28
  • Hi @VonC, so what do you do when removing the tags is not a suitable fix for your particular use case? – Guillius Apr 12 '23 at 13:59
  • @Guillius I would first check if this is still valid in 2023: Git has changed a lot since my 2012 answer. Then I would clone *without* tags, and import only the tags I need. – VonC Apr 12 '23 at 18:25
  • @VonC it still seems to be the case. When I cloned without tags, the refs to branches would cause the same issue (because I use a lot of submodules), so then I configured shallow cloning as well, eventually fixing my problems. Thanks a lot, your answer really put me on the right track! – Guillius Apr 14 '23 at 13:30
2

This is really embarrassing but the real problem was with my firewall Comodo Firewall which somehow was blocking the ssh connection from being initialized by git.

I can without any problems connect via ssh e.g. using command line or Putty but somehow Comodo was causing this weird issue.

Thanks everyone for support!

Patryk
  • 22,602
  • 44
  • 128
  • 244
2

i think a path (ex: C:\Program Files (x86)\Git) having blank space so it cannot recognise.

to resolve it

  • make a simple link to shorten path

    mklink /d "C:/Git" "C:\Program Files (x86)\Git"

it works for me and also for Jenkins (if you use it with Git plugin)

  • set GIT_SSH=C:\Git
  • Finally, set PATH to %GIT_SSH%\bin
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
biolinh
  • 2,175
  • 1
  • 24
  • 23
  • Can't work on my Windows 10 system, since an executable needs to be pointed by `%GIT_SSH%`. Anyway, the problem is not that git can't find it, but rather that it can't *spawn* it. *Access denied*, whatever permissions I set on. Also, On more recent distros, the binaries are rather located in `%GIT_SSH%\usr\bin` – Fabien Haddadi Sep 16 '21 at 10:22
  • YES. This is because you are trying to spawn a 64-bit executable from a 32-bit executable, and THE SYSTEM DIRECTORIES ARE VIRTUAL IN THIS CASE. This is an advanced topic that you are normally totally isolated from, and most people feel really offended when they run into it the first time, but basically "System32" doesn't do what you expect in this case-- not even close. Look up "SysNative" vs "System32", and then try this: GIT_SSH='"C:\\Windows\\SysNative\\OpenSSH\\ssh.exe"' This is ONLY valid for Windows 10 build 1803 or later (circa 2018-2019). Note BOTH sets of quotes. – breakpoint Feb 19 '22 at 09:15
1

For anyone who finds this post, but has an error message that ressembles the following (Permission denied):

error: cannot spawn C:\Program Files\OpenSSH\: Permission denied
fatal: unable to fork

In my case, the error was that GIT_SSH pointed to the directory C:\Program Files\OpenSSH\ and not to the file C:\Program Files\OpenSSH\ssh.exe. After fixing this, git worked both in PowerShell and bash.

Markus
  • 20,838
  • 4
  • 31
  • 55
  • *IMPORTANT:* Please note that this is NOT CORRECT if you are explicitly trying to use Windows' internal, native, OpenSSH feature (available since Windows 10 1803). In that case, the correct reference would be: C:\Windows\SysNative\OpenSSH\ssh.exe Further, if you are trying to integrate things with Visual Studio 2022, the correct way to specify this in your %UserProfile%/.gitconfig, is STRICTLY, EXACTLY, AND *PRECISELY* this: [core] sshcommand = '"C:\\Windows\\SysNative\\OpenSSH\\ssh.exe"' Note the single quotes SURROUNDING the double-quotes, and "SysNative". – breakpoint Feb 19 '22 at 09:05
  • 1
    @breakpoint I wanted explicitely to use another SSH client and not the Windows out-of-the-box client due to the long update cycles. Using the GIT_SSH environment variable also works for Visual Studio 2022, Visual Studio Code and other Git clients - at least on the boxes in our company. – Markus Feb 21 '22 at 09:42
  • 1
    The long update cycles are an interesting point. Good to hear that you had luck using the environment variable to the same effect, I may wind up having to do that on one machine myself, so thanks for the follow-up. – breakpoint Feb 23 '22 at 10:07
  • setting GIT_SSH with the value specified by @breakpoint for sshcommand did not work for me – Dariopnc May 03 '22 at 14:11
0

On my windows 7 default ms git bash installation I needed to set GIT_SSH to:

"C:\\Program Files (x86)\\Git\\bin\\ssh.exe"

So just find your ssh.exe provided with Git installation and update the above with correct dir.

To make this persistent every time you run git bash just add your home dir in .bashrc file this:

export GIT_SSH="C:\\Program Files (x86)\\Git\\bin\\ssh.exe"
Mareker
  • 1
  • 1
  • 1
0

If You are using Windows PowerShell then please try to set proper path to GIT_SSH. In my case:

PS C:\some\path> $env:GIT_SSH="C:\Program Files\PuTTY\plink.exe"
lu_ko
  • 4,055
  • 2
  • 26
  • 31
-1

I was constantly getting the error

error: cannot spawn "C:\Plink.exe": No such file or directory fatal: unable to fork

when doing git push and git pull. I solved it by going into the .git/config file and changing

url = git@github.com:<USER>/<REPO>.git

to

url = https://github.com/<USER>/<REPO>

Hope this helps!

andrewzm
  • 450
  • 2
  • 7
-1

I also had the same issue, an antivirus software blocked the ssh agent from executing. Uninstalling the antivirus software work for me.

  • This is a duplicate of an of existing answer, by @VonC. When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers. Remember to review all existing answers first. – tjheslin1 Apr 07 '22 at 15:50