"Cannot spawn ssh" when connecting to Github, but ssh -T git@github.com works?

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?


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

In my case setting GIT_SSH to:

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

worked in git bash.

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.

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.

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.


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

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!

  • 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.
  • @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.
  • 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.
  • @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
  • Was I correct that the folder containing ssh is in PATH?
  • 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.
  • 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
  • @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.
  • What do you mean by 'installing ssh.exe' ? Which ssh so you mean here? OpenSSH ? Git's ssh ?
  • 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.
  • Where should I test quoting backslashes ? In the PATH ? If not then were ?
  • I would test installing git's ssh.exe to a path without spaces first (eg. "c:\git")! See this comment: code.google.com/p/msysgit/issues/detail?id=313#c3