“Cannot spawn ssh” when connecting to Github, but

2019-02-03 02:08发布

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

8条回答
祖国的老花朵
2楼-- · 2019-02-03 02:42

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"
查看更多
相关推荐>>
3楼-- · 2019-02-03 02:47

In my case setting GIT_SSH to:

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

worked in git bash.

查看更多
看我几分像从前
4楼-- · 2019-02-03 02:54

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!

查看更多
Melony?
5楼-- · 2019-02-03 02:54

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.

查看更多
三岁会撩人
6楼-- · 2019-02-03 02:59

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
查看更多
趁早两清
7楼-- · 2019-02-03 03:00

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.

查看更多
登录 后发表回答