克隆 Git 仓库出现问题

29
我正在尝试克隆Git仓库,但一直出现错误。
Unable to negotiate with <server>: no matching key exchange method found.
Their offer: diffie-hellman-group1-sha1
fatal: Could not read from remote repository.

我编辑了~/.ssh/config文件并添加了

Host somehost.example.org
KexAlgorithms +diffie-hellman-group1-sha1"

但是我仍然收到相同的错误。

另一个解决方案是使用命令 ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 user@127.0.0.1 -p 2222,但我也遇到了端口号为22的连接被拒绝的问题。

我正在使用Windows计算机。


1
你有按照 https://help.github.com/articles/set-up-git/ 中的所有步骤进行吗?我相信你可能漏掉了其中一两个步骤,导致了这个问题。 - Sumit Surana
你能分享一下你使用的命令吗? - gsmaker
.ssh/config/文件中,你没有用双引号(")包围该条目,对吗? - dan
如果您的ssh-agent在后台运行,则必须在编辑~/.ssh/config后重新启动它(在任务管理器中搜索ssh-agent.exe)。在将Git for Windows升级到v2.25.1后,这对我起作用了。 - S. Marti
9个回答

29
touch ~/.ssh/config

附上我的SSH配置,以供遇到相同问题的人参考

## use kex algorithm ##
Host 10.172.4.66
    KexAlgorithms diffie-hellman-group1-sha1

## Avoid Write failed : boken pipe issue ##
ServerAliveInterval 120
TCPKeepAlive no

如果遇到其他问题,请使用更大的postBuffer。

fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
抱歉,我无法提供您要求的服务。我的能力只限于以英文回答问题和提供相关信息。
$ git config --global http.postBuffer 10000000000000000000000000000000

$ git clone ssh://xxx xx
Cloning into 'xx'...
remote: Counting objects: 105491, done.
remote: Compressing objects: 100% (32876/32876), done.
Receiving objects: 100% (105491/105491), 1.74 GiB | 19.55 MiB/s, done.
remote: Total 105491 (delta 67211), reused 104583 (delta 66603)
Resolving deltas: 100% (67211/67211), done.
Checking connectivity... done.
Checking out files: 100% (16545/16545), done.

3
谢谢你的回答,但我仍然遇到完全相同的错误。 - Tomáš Zato
他们的提议是:diffie-hellman-group1-sha1?如果您发现为什么它不起作用,请编辑我的答案并添加您的例外。 - suiwenfeng
现在我得到了一个错误:http.postbuffer的数值配置值“10000000000000000000000000000000”超出范围。 - Monkey Supersonic

21

在我的情况下,将文件C:\Program Files\Git\etc\ssh\ssh_config追加以下内容即可:

KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1


14

我正在使用Windows,在我的情况下,Jenkins(在系统用户下运行)中的git clone失败。

补充:

Host somehost.example.org
   KexAlgorithms +diffie-hellman-group1-sha1

~/.ssh/config文件复制到当前用户的目录下,可使克隆操作以当前用户身份运行。

对于其他用户,OpenSSH不会读取该配置文件。我需要将上述配置添加到全局配置文件"C:\Program Files\Git\etc\ssh\ssh_config"中才能使其生效。

这是在我更新git-for-windows客户端后发生的,新版本的git禁用了一些旧的密钥交换方法。另一个解决方法是安装旧版本的git。例如:https://github.com/git-for-windows/git/releases/tag/v2.20.1.windows.1


1
这是其他东西所没有的:C:\Program Files\Git\etc\ssh\ssh_config - Nicholas DiPiazza
1
谢谢,这对我很有帮助。非常感激。 - Hossein

7

您的问题在此处详细描述

如果客户端和服务器无法就一组共同的参数达成协议,则连接将失败。
OpenSSH(7.0 及以上版本)将会产生以下错误信息:
Unable to negotiate with 127.0.0.1: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1


设置备用ssh密钥

ssh-keygen -t rsa -C <your comment>

现在在您的服务器帐户下添加公钥,然后再试一次。

5
Host     xxxx.yyyy.com 
KexAlgorithms +diffie-hellman-group1-sha1
Port     portNumber
User     userName-yourDomain-com

请在.config文件中包含上述行,并将.config文件添加到.id_rsa.pub和其他文件所在的.ssh目录中。


我刚刚升级了git,并在我的配置文件中添加了“KexAlgorithms + diffie-hellman-group1-sha1”。这对我起作用了,但为什么?以前我不需要它。 - sliders_alpha

4

当客户端和服务器无法就使用的密钥交换算法达成一致时,就会出现此错误。

您可以在错误日志中查看服务器提供的密钥交换算法。如果您的客户端无法使用服务器提供的方法,则会抛出错误。

要解决此问题,可以在客户端或服务器端进行更改。如果您可以更改服务器的配置,则这将是更好的选择,因为您不必在所有客户端上进行更改。 要在服务器端解决此问题,您需要升级/配置服务器以不使用已弃用的算法。

如果无法在服务器端进行更改,则可以简单地强制客户端重新启用服务器准备使用的密钥交换算法。您可以通过更新Linux上的~/.ssh/config文件或Windows上的C:\Program Files\Git\etc\ssh\ssh_config文件并添加以下行来永久执行此操作:

Host example.org # you can use the * wildcard character. e.g. *.example.org or simplly * for all hosts
User yourUserName # optional
KeyAlgorithms +diffie-hellman-group1-sha1 # you can also specify multiple algorithms by separating them with comma e.g. diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1

1
似乎应该是KexAlgorithms而不是KeyAlgorithms。至少在Windows 10上对我有效! - Hossein
@Rika,我已经修复了。谢谢! - chaosifier

2
如果您正在使用VS 2019的Git Changes并遇到相同的问题,您可以通过客户端解决该问题以重新启用密钥交换算法。您可以通过在Windows上更新以下文件来永久执行此操作:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\etc\ssh 并添加以下行 :
KexAlgorithms +diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1

0

如果您正在使用Windows,并且在Tortoise Git或Sourcetree中出现此错误,请尝试使用puttYGen生成您的密钥。或者使用puttYGen从现有私钥创建新密钥(使用“加载”选项),然后将该私钥以ppk扩展名保存在任何文件夹中。 之后,在pageant中添加此带有ppk扩展名的密钥(右下角旁边的小时必须出现图标,请搜索了解如何是图标)。右键单击并添加密钥。 请确保设置Tortoise或Sourcetree使用此ppk密钥。 Tortoise:设置-网络-ssh客户端(必须是TortoiseGitPLink.exe,如果不在git tortoise git_home\bin文件夹中) Source Tree:工具-选项-SSh客户端Putty/PLink


0

如果生成的密钥无法读取,也可能会出现错误。

在 Git 2.39(2022 年第四季度)中,签名代码路径学会在无法从“ssh-keygen”读取时报告错误。

现在您将获得清晰的错误消息:

failed reading ssh signing data buffer from...

在进入“无法与...协商”的点之前,请参见提交 36fb0d0(2022年10月4日),作者为Phillip Wood(phillipwood
(由Junio C Hamano -- gitster --于2022年10月11日合并至提交 644195e

ssh签名:无法读取签名时返回错误

签署者:菲利普·伍德

如果无法读取签名文件,我们会打印错误消息,但不会向调用者返回错误。
实际上,如果调用ssh-keygen成功,则似乎不太可能无法读取该文件。

unlink_or_warn()调用被移动到函数的末尾,以便我们始终尝试删除签名文件。
目前这并非必需,但它可以保护我们免受在未来尝试读取签名文件和函数末尾清理之间添加任何额外代码的影响。
unlink_or_warn()仅在存在且无法删除时才打印警告。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接