我正试图从我的BitBucket帐户克隆一个回购到我的Windows 10笔记本电脑(运行GitBash)。我已经完成了连接所需的所有步骤(设置我的SSH密钥,通过成功SSHing git@bitbucket.org验证,等等)。然而,每当我试图克隆一个回购,提示不断挂断后,确认我想要缓存Bitbucket的密钥。

User@Laptop MINGW64 /C/Repos
$ git clone git@bitbucket.org: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

没有文件被克隆,结果是一个空的repo。试图从这个repo启动一个git pull origin master也要求缓存键,然后挂起没有反馈。尽管我在测试SSH时没有请求缓存密钥,但git操作总是在每次失败前都请求密钥。

由于没有可以处理的错误消息,我真的不知道哪里出了问题。我尝试过多次回购,包括非常小的回购,但都没有成功。


当前回答

开放的腻子 输入主机名(如bitbucket.org) 点击打开 在弹出窗口中单击是以缓存主机密钥 关闭腻子

其他回答

默认SSH连接端口为7999

如果你使用KiTTY(而不是PuTTY),它有-auto-store-sshkey参数。

因此,你可以将GIT_SSH_COMMAND(或git config——global core.sshCommand)设置为c:/KiTTY/klink.exe -auto-store-sshkey。

输出仍然包含关于新键和问题的信息,但它不会等待答案:

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 ssh-ed25519 key fingerprint is:
ssh-ed25519 255 2e:65:6a:c8:cf:bf:b2:8b:9a:bd:6d:9f:11:5c:12:16
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)
Autostore key is on

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

我通过使用Putty GUI来SSH到有问题的服务器(在您的情况下:bitbucket.org),然后在提示询问是否要将服务器密钥保存到缓存时单击“Yes”。再次运行克隆命令,然后为我工作!

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

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

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

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

或设置GIT_SSH_COMMAND环境变量。

当你从未知主机克隆一个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.

在此消息之后,您可以使用命令添加一个密钥到缓存:

echo y | plink git@bitbucket.org

注意:请检查plink是否在您的PATH中。或者在git配置选项中使用类似unix的路径,例如:

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