连接到 Github 时“无法生成 ssh”,但 ssh -T [email protected] 有效吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10574267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:41:14  来源:igfitidea点击:

"Cannot spawn ssh" when connecting to Github, but ssh -T [email protected] works?

gitversion-controlsshgithub

提问by Patryk

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

我很难让 Github(+Netbeans 工作)。

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 :

我想将 ssh 与 git(在 Windows 7 上)一起使用,例如,提交或克隆一个项目,但我不断收到此错误消息:

$ git clone [email protected]: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_SSHenvironment 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.

注意:目前,我的GIT_SSH环境变量指向C:\Program Files (x86)\Git\bin\ssh.exe,但我也尝试过C:\Program Files (x86)\Git\bin,完全擦除它,指向 putty/plink 的文件夹,并指向它们的可执行文件,但仍然是相同的消息。

When I test the connection everything works fine:

当我测试连接时一切正常:

$ ssh -T [email protected]
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 initin the directory in the first place?

我究竟做错了什么?如果我git init首先在目录中执行该操作会有所不同吗?

EDIT:

编辑

This didn't help:

这没有帮助:

setting GIT_SSHto plink.exeand adding plink's path to PATH

设置GIT_SSHplink.exe并加入砰砰的路径PATH

**EDIT 2 **

**编辑 2 **

result of command with GIT_TRACE=2

命令的结果 GIT_TRACE=2

$ GIT_TRACE=2 git clone [email protected]:XXX/AffableBean
trace: built-in: git 'clone' '[email protected]:XXX/AffableBean'
Cloning into 'AffableBean'...
trace: run_command: 'Plink.exe' '-batch' '[email protected]' 'git-upload-pack '\''XXX/AffableBean'\'''
error: cannot spawn Plink.exe: No such file or directory
fatal: unable to fork

采纳答案by Patryk

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

这真的很尴尬,但真正的问题是我的防火墙Comodo Firewall以某种方式阻止了 ssh 连接被git.

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

我可以毫无问题地通过 ssh 连接,例如使用命令行或 Putty,但不知何故Comodo导致了这个奇怪的问题。

Thanks everyone for support!

感谢大家的支持!

回答by schoetbi

In my case setting GIT_SSH to:

在我的情况下,将 GIT_SSH 设置为:

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

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

worked in git bash.

在 git bash 中工作。

回答by cgchoffman

None of the answers so far worked for me. What ended up fixing this issue for me was removing quotes from my GIT_SSHvariable 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.

到目前为止,没有一个答案对我有用。最终为我解决这个问题的是从我的GIT_SSH变量中删除引号并且根本不转义任何字符,没有 MSYS 路径样式(例如/c/path\ to\ putty/plink.exe)。正常输入路径,Git 处理引用。

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:

就是这样。使用 GIT_TRACE 时,您可以看到该变量在结果命令中被引用,因此:

  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.

  1. 添加的双引号更改传递给命令的字符串和

  2. 路径用单引号括起来,所以空格没问题。

Hope that helps someone.

希望能帮助某人。

回答by user1338062

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

您是否尝试将 ssh.exe 安装到不包含空格的路径?您是否测试过引用反斜杠是否有效 ( \\)?

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

您也可以尝试GIT_TRACE=2 git clone <...>,它应该会显示 git 尝试运行以进行连接的命令和参数。

回答by yoshy27

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

就我而言,我能够通过在 CMD 终端中创建目录连接并重置 GIT_SSH 来解决该问题。

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

通过在 Git Bash 终端中运行此 Windows CMD 命令来查找 ssh 命令的路径。

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

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

在 CMD 终端中为原始 Git 目录创建一个没有空格的结点。

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.

然后编辑 GIT_SSH 环境变量以使用联结。对于 Windows 7,控制面板 > 系统和安全 > 系统 > 高级系统设置。

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.

在将 PuTTY 用法切换到 OpenSSH 后,我以某种方式遇到了这个问题。git 版本是 2.21.0.windows.1。我希望这有帮助。

回答by biolinh

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

我认为路径(例如:C:\Program Files (x86)\Git)有空格所以它无法识别。

to resolve it

解决它

  • make a simple link to shorten path

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

  • 制作一个简单的链接以缩短路径

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

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

它对我和 Jenkins 都有效(如果你将它与 Git 插件一起使用)

  • set GIT_SSH=C:\Git
  • Finally, set PATH to %GIT_SSH%\bin
  • 设置 GIT_SSH=C:\Git
  • 最后,将 PATH 设置为 %GIT_SSH%\bin

回答by VonC

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

除非您有一些晦涩的防病毒交互,否则看到此错误消息的唯一其他情况(除了您所指的问题 313)是:

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

错误:无法生成 git:没有这样的文件或目录

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.

如果您遇到此错误“ error: cannot spawn git: No such file or directory”,那真是一个令人讨厌的问题。
我花了一天的时间来追踪它,但归结为如果存储库中有超过 500 个标签,它必须破坏一些内部命令行限制。
TLDR:如果您收到此错误,请删除一堆标签。

回答by Mareker

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

在我的 Windows 7 默认 ms git bash 安装中,我需要将 GIT_SSH 设置为:

"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.

因此,只需找到随 Git 安装提供的 ssh.exe 并使用正确的目录更新上述内容。

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

要在每次运行 git bash 时保持持久性,只需在 .bashrc 文件中添加您的主目录:

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

回答by andrewzm

I was constantly getting the error

我不断收到错误

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

错误:无法生成“C:\Plink.exe”:没有这样的文件或目录致命:无法分叉

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

当做git pushgit pull。我通过进入 .git/config 文件并更改来解决它

url = [email protected]:<USER>/<REPO>.git

url = [email protected]:<USER>/<REPO>.git

to

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

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

Hope this helps!

希望这可以帮助!