windows Git clone / pull 在“将密钥存储在缓存中?”时不断冻结?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33240137/
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-08 19:18:18  来源:igfitidea点击:

Git clone / pull continually freezing at "Store key in cache?"

windowsgitsshversion-controlbitbucket

提问by MarathonStudios

I'm attempting to clone a repo from my BitBucket account to my Windows 10 laptop (running GitBash). I've completed all of the steps necessary to connect (set up my SSH key, verified by successfully SSHing [email protected], etc). However, whenever I attempt to clone a repo, the prompt continually hangs up after confirming that I want to cache Bitbucket's key.

我正在尝试将我的 BitBucket 帐户中的存储库克隆到我的 Windows 10 笔记本电脑(运行 GitBash)。我已经完成了连接所需的所有步骤(设置了我的 SSH 密钥,通过 SSH 成功验证 [email protected] 等)。但是,每当我尝试克隆存储库时,在确认我要缓存 Bitbucket 的密钥后,提示会不断挂断。

User@Laptop MINGW64 /C/Repos
$ git clone [email protected]:mygbid/test.git
Cloning into 'test'...
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) y

No files are cloned, and the result is an empty repo. Trying to initiate a git pull origin master from this repo also asks to cache the key, then hangs with no feedback. Despite not asking for the key to be cached when I do a test SSH, git operations always ask for the key every time before failing.

没有文件被克隆,结果是一个空的 repo。尝试从此 repo 启动 git pull origin master 也会要求缓存密钥,然后在没有反馈的情况下挂起。尽管在我进行 SSH 测试时不要求缓存密钥,但每次 git 操作在失败之前总是要求提供密钥。

With no error messages to work with, I'm really at a loss as to what is wrong. I've tried multiple repos, including very small ones, with no success at all.

由于没有可处理的错误消息,我真的不知道出了什么问题。我尝试了多个 repos,包括非常小的 repos,但根本没有成功。

回答by theChumpus

I had this problem when cloning a repo on Windows 10 too.

在 Windows 10 上克隆 repo 时我也遇到了这个问题。

I got around it by using the Putty GUI to SSH to the server in question (in your case: bitbucket.org) then clicked 'Yes' when the prompt asks if you want to save the server key to the cache. Running the clone command again then worked for me!

我通过使用 Putty GUI 通过 SSH 连接到相关服务器(在您的情况下:bitbucket.org)解决了这个问题,然后当提示询问您是否要将服务器密钥保存到缓存时单击“是”。再次运行克隆命令然后对我来说有效!

回答by cambunctious

  1. Open Putty
  2. Type in the Host Name (like bitbucket.org)
  3. Click Open
  4. Click yes in the popup to cache the host key
  5. Close Putty
  1. 打开腻子
  2. 输入主机名(如bitbucket.org
  3. 点击打开
  4. 在弹出窗口中单击是缓存主机密钥
  5. 关闭腻子

回答by Tim Abell

To do this from powershell open a powershell window and paste in the following:

要从 powershell 执行此操作,请打开一个 powershell 窗口并粘贴以下内容:

echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh [email protected]
echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh [email protected]
echo y | & 'C:\Program Files (x86)\GitExtensions\PuTTY\plink.exe' -ssh [email protected]

or with PuTTY standalone version:

或使用 PuTTY 独立版本:

echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh [email protected]
echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh [email protected]
echo y | & 'C:\Program Files (x86)\PuTTY\plink.exe' -ssh [email protected]

Also worth knowing is that putty stores known hosts under a registry key:

同样值得了解的是,腻子将已知主机存储在注册表项下

HKEY_CURRENT_USER\SoftWare\SimonTatham\PuTTY\SshHostKeys

To shortcut the above you could put the following in a .regfile and run it:

要快捷方式以上,您可以将以下内容放入.reg文件中并运行它:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\SimonTatham\PuTTY\SshHostKeys]
"rsa2@22:github.com"="0x23,0xab603b8511a67679bdb540db3bd2034b004ae936d06be3d760f08fcbaadb4eb4edc3b3c791c70aae9a74c95869e4774421c2abea92e554305f38b5fd414b3208e574c337e320936518462c7652c98b31e16e7da6523bd200742a6444d83fcd5e1732d03673c7b7811555487b55f0c4494f3829ece60f94255a95cb9af537d7fc8c7fe49ef318474ef2920992052265b0a06ea66d4a167fd9f3a48a1a4a307ec1eaaa5149a969a6ac5d56a5ef627e517d81fb644f5b745c4f478ecd082a9492f744aad326f76c8c4dc9100bc6ab79461d2657cb6f06dec92e6b64a6562ff0e32084ea06ce0ea9d35a583bfb00bad38c9d19703c549892e5aa78dc95e250514069"
"rsa2@22:gist.github.com"="0x23,0xab603b8511a67679bdb540db3bd2034b004ae936d06be3d760f08fcbaadb4eb4edc3b3c791c70aae9a74c95869e4774421c2abea92e554305f38b5fd414b3208e574c337e320936518462c7652c98b31e16e7da6523bd200742a6444d83fcd5e1732d03673c7b7811555487b55f0c4494f3829ece60f94255a95cb9af537d7fc8c7fe49ef318474ef2920992052265b0a06ea66d4a167fd9f3a48a1a4a307ec1eaaa5149a969a6ac5d56a5ef627e517d81fb644f5b745c4f478ecd082a9492f744aad326f76c8c4dc9100bc6ab79461d2657cb6f06dec92e6b64a6562ff0e32084ea06ce0ea9d35a583bfb00bad38c9d19703c549892e5aa78dc95e250514069"
"rsa2@22:bitbucket.org"="0x23,0xb9b88df3578371a7eb80c78bcda14fb30da436f11ca932a5fd5a8b6adfcc681df7a59cb4cb7ac966d9eac11daa38ebdbc0a6582a210ed4ee95a8d101c4abc925e942ab47535d64f9a5b3b68035c2ea1e900d709a1e8ea938718f532f9805a190446b92bac3040126225ae9d8374bc2008f106979d631734c7453f78c70091f4783b288869cb3c1941a784cd9baad823be27333833dc1f488a45b85952be75cf0a64965662302e3915378dcd5cfcd3ec903d804a29dff2fdf19df5deba4534b09e4dea6e44f152e339b3c43be98ddadfc56533192e216a3d673f00b4aa9cc9e7870acd8b6adb7e0feb77f2292fc2dede94819def3eb1e785541a06ab31ccf725f"

putty-hosts.reg gist

putty-hosts.reg 要点

回答by benjaminRRR

I managed to get it working by running plink directly, after pageant is running use the plink command directly - plink.exe -agent -v [email protected]then after this git works without hanging.

我设法通过直接运行 plink 使其工作,在 pageant 运行后直接使用 plink 命令 -plink.exe -agent -v [email protected]然后在此 git 工作后没有挂起。

回答by frenchu

To workaround this problem I configured GitBash to use plink with -batchoption. The option disables all prompts - the plink will terminate without hanging and won't add any key fingerprint to cache.

为了解决这个问题,我将 GitBash 配置为使用带有-batch选项的plink 。该选项禁用所有提示 - plink 将终止而不会挂起,并且不会向缓存添加任何密钥指纹。

To add -batchparameter to plink command executed by GitBash you can set a git config option:

要将-batch参数添加到由 GitBash 执行的 plink 命令,您可以设置一个 git 配置选项:

git config --global core.sshCommand "plink -batch"

Or set GIT_SSH_COMMANDenvironment variable.

或者设置GIT_SSH_COMMAND环境变量。

The output when you cloning a repo from unknown host will be similar to this:

从未知主机克隆 repo 时的输出将类似于以下内容:

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
Connection abandoned.
fatal: Could not read from remote repository.

After this message you can add a key to cache with command:

在此消息之后,您可以使用以下命令添加要缓存的密钥:

echo y | plink [email protected]

REMARK: Please check if plink is in your PATH. Alternatively use UNIX-like path in the GitBash config option, e.g.:

备注:请检查 plink 是否在您的PATH. 或者在 GitBash 配置选项中使用类 UNIX 路径,例如:

/c/Program\ Files/PuTTY/plink.exe -batch

回答by Schparky

Even after performing the workaround mentioned in other answers, you may encounter an error like:

即使在执行了其他答案中提到的解决方法之后,您也可能会遇到如下错误:

FATAL ERROR: Disconnected: No supported authentication methods available (server sent: publickey)

致命错误:断开连接:没有可用的受支持的身份验证方法(服务器发送:公钥)

To solve both problems at once, change git bash to use SSH instead of PuTTY by adding the following to your ~/.profilefile (C:\Users\<Username>\.profile). If you don't already have this file, then create a new file with this line.

要同时解决这两个问题,请通过将以下内容添加到您的~/.profile文件 ( C:\Users\<Username>\.profile) 中,将 git bash 更改为使用 SSH 而不是 PuTTY 。如果您还没有此文件,请使用此行创建一个新文件。

GIT_SSH="/usr/bin/ssh.exe"

Then open a new git bash window and try your git cloneor git pullagain.

然后打开一个新的Git的bash窗口,并尝试git clonegit pull一次。

Note that this may require you to create an SSH key if you don't already have one. To do this, follow the instructions on the Bitbucketsite.

请注意,如果您还没有 SSH 密钥,这可能需要您创建一个。为此,请按照Bitbucket站点上的说明进行操作。

See this SO questionfor related info.

有关相关信息,请参阅此 SO 问题

回答by Richard Jessop

In your git bash shell, check for existence of GIT_SSH:
echo $GIT<tab><tab>
If it exists and is set to putty, execute:
unset GIT_SSH
You'll probably want to put this into one of the git bash startup scripts.
This is NOT a universal solution. It worked in our particular case.

在您的 git bash shell 中,检查 GIT_SSH 是否存在:
echo $GIT<tab><tab>
如果它存在并设置为 putty,请执行:
unset GIT_SSH
您可能希望将其放入其中一个 git bash 启动脚本中。
这不是一个通用的解决方案。它在我们的特殊情况下有效。

回答by Vlad

It sounds a bit silly, but after trying all of the above, I decided to reinstall Git Bash with default options and it worked.

这听起来有点傻,但是在尝试了上述所有方法之后,我决定使用默认选项重新安装 Git Bash 并且它起作用了。