【问题标题】:Issue with cloning git repository克隆 git 存储库的问题
【发布时间】:2021-09-17 14:25:06
【问题描述】:

我正在尝试克隆 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机器。

【问题讨论】:

  • 您是否按照help.github.com/articles/set-up-git 中的所有步骤进行操作?我相信您已经遗漏了一两件事,导致了这个问题。
  • 你能分享你使用的命令吗?
  • .ssh/config/ 中,您没有用双引号 (") 将条目括起来,对吧?
  • 如果你有ssh-agent在后台运行,你必须在编辑~/.ssh/config后重启它(在任务管理器中搜索ssh-agent.exe)。在将 Git for Windows 升级到 v2.25.1 后,这对我有用。

标签: git ssh


【解决方案1】:
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.

【讨论】:

  • 感谢您的回答,但我仍然收到完全相同的错误。
  • 他们的报价:diffie-hellman-group1-sha1?如果您发现它为什么不起作用,请编辑我的答案添加您的例外情况。
  • 现在我得到bad numeric config value '10000000000000000000000000000000' for 'http.postbuffer': out of range
【解决方案2】:

附加文件 C:\Program Files\Git\etc\ssh\ssh_config 对我有用:

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

【讨论】:

    【解决方案3】:

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

    添加

    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

    【讨论】:

    • 这是其他人没有的东西:C:\Program Files\Git\etc\ssh\ssh_config
    • 感谢这对我有用。非常感谢它
    【解决方案4】:

    你的问题详细描述here:

    如果客户端和服务器无法就一组相互的参数达成一致,则连接将失败。
    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 文件中包含以上行,并在 id_rsa.pub 和其他文件所在的 .ssh 目录中添加 .config 文件。

      【讨论】:

      • 我刚刚升级了 git,并在我的配置文件中添加了KexAlgorithms +diffie-hellman-group1-sha1,这对我有用,但为什么呢?我以前不需要它。
      【解决方案6】:

      当客户端和服务器无法就要使用的密钥交换算法达成一致时,会发生此错误。 您可以在错误日志中看到服务器提供使用的密钥交换算法。如果您的客户端无法使用服务器提供的方法,则会引发错误。 要解决此问题,可以在客户端或服务器端进行更改。如果您可以更改服务器的配置,那将是更好的选择,因为您不必在所有客户端中进行更改。 要解决服务器端的问题,您需要升级/配置服务器以不使用已弃用的算法。

      如果无法在服务器端进行更改,可以简单地强制客户端重新启用服务器已准备好使用的密钥交换算法。您可以通过更新 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
      KexAlgorithms +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
      

      【讨论】:

      • 似乎应该是KexAlgorithms 而不是KeyAlgorithms。至少这在 Windows 10 上对我有用!
      • @Rika,我已经修好了。谢谢!
      【解决方案7】:

      如果您使用的是 windows 并且这个错误发生在 tortoise Git 或 Sourcetree 中,请尝试使用 puttYGen 生成您的密钥。或者使用 puttYGen(使用加载选项)从您现有的私钥创建一个新密钥,然后将该私钥以扩展名 ppk 保存在任何文件夹中。 之后,在选美比赛中添加这个键(扩展名为ppk)(谷歌知道图标是怎么回事,它必须出现在小时旁边的右下角)右键单击并添加键。 尝试确保您设置您的乌龟或您的源树以使用此 ppk 密钥。 Tortoise:设置 - 网络 - ssh 客户端(必须是 TortoiseGitPLink.exe,如果不是在 git tortoise git_home\bin 文件夹中) 源码树:工具-选项-SSH客户端Putty/PLink

      【讨论】:

        【解决方案8】:

        如果您使用 VS 2019 的 Git Changes 并遇到同样的问题,您可以从客户端解决问题以重新启用密钥交换算法。您可以通过更新 C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\etc\ssh 永久执行此操作windows 上的文件并添加以下行:

        KexAlgorithms +diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-07-14
          • 1970-01-01
          • 1970-01-01
          • 2018-03-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多