简体   繁体   English

克隆git存储库的问题

[英]Issue with cloning git repository

I am trying to clone the git repository and i am getting error我正在尝试克隆 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.

I edited ~/.ssh/config and added我编辑了~/.ssh/config并添加了

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

but still I am getting same error.但我仍然遇到同样的错误。

Other solution is to use the command ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 user@127.0.0.1 -p 2222 but I am getting connection refused with port no 22 as well.其他解决方案是使用命令ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 user@127.0.0.1 -p 2222但我的连接也被拒绝,端口号为 22。

I am using windows machine.我正在使用 Windows 机器。

touch ~/.ssh/config

attach my ssh config for people who come across the same issue为遇到相同问题的人附上我的 ssh 配置

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

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

use larger postBuffer if come accross another issue如果遇到另一个问题,请使用更大的 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.

Appending the file C:\\Program Files\\Git\\etc\\ssh\\ssh_config with below content worked for me:使用以下内容附加文件C:\\Program Files\\Git\\etc\\ssh\\ssh_config对我有用

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

( Cheers 🍻 ) (干杯🍻)

I am using windows, for my case git clone fails in Jenkins (running under system user).我正在使用 Windows,因为我的情况 git clone 在 Jenkins 中失败(在系统用户下运行)。

Adding添加

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

into ~/.ssh/config will make the clone running as the current user works.进入~/.ssh/config将使克隆在当前用户工作时运行。

For other users , the OpenSSH won't pick up the config.对于其他用户,OpenSSH 不会选择配置。 I have to add the above config into the global config file: "C:\\Program Files\\Git\\etc\\ssh\\ssh_config" to make it work.我必须将上述配置添加到全局配置文件中: “C:\\Program Files\\Git\\etc\\ssh\\ssh_config”才能使其工作。

This happens after I updated the git-for-windows client, new git disable some old key exchange method.这发生在我更新了 git-for-windows 客户端之后,新的 git 禁用了一些旧的密钥交换方法。 Another work around is install older version of git.另一种解决方法是安装旧版本的 git。 eg: https://github.com/git-for-windows/git/releases/tag/v2.20.1.windows.1例如: https : //github.com/git-for-windows/git/releases/tag/v2.20.1.windows.1

Your problem is described in details here :您的问题在此处详细描述:

If the client and server are unable to agree on a mutual set of parameters then the connection will fail.如果客户端和服务器无法就一组相互的参数达成一致,则连接将失败。
OpenSSH (7.0 and greater) will produce an error message like this: OpenSSH(7.0 及更高版本)将产生如下错误消息:
Unable to negotiate with 127.0.0.1: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1


Setting alternate ssh keys设置备用 ssh 密钥

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

now add the public key under your server account and try again.现在在您的服务器帐户下添加公钥并重试。

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

Include above lines in .config file and add .config file in .ssh directory where id_rsa.pub and other files are located.在 .config 文件中包含以上行,并在 id_rsa.pub 和其他文件所在的 .ssh 目录中添加 .config 文件。

This error occurs when the client and server are unable to agree on the key exchange algorithm to use.当客户端和服务器无法就要使用的密钥交换算法达成一致时,就会发生此错误。 You can see in the error log what key exchange algorithms the server is offering to use.您可以在错误日志中看到服务器提供使用的密钥交换算法。 In case when your client is unable to work with the methods offered by the server, the error is thrown.如果您的客户端无法使用服务器提供的方法,则会引发错误。 To fix this issue changes can be made on the client or server side.要解决此问题,可以在客户端或服务器端进行更改。 If you can change the server's configuration, that would be the better path to take as you wouldn't have to make changes in all clients.如果您可以更改服务器的配置,那将是更好的选择,因为您不必对所有客户端进行更改。 To fix the issue on the server side, you need to upgrade/configure the server to not use deprecated algorithms.要解决服务器端的问题,您需要升级/配置服务器以不使用不推荐使用的算法。

If change on the server side is not possible, one could simply force the client to re-enable the key exchange algorithms the server is ready to work with.如果无法在服务器端进行更改,则可以简单地强制客户端重新启用服务器准备使用的密钥交换算法。 You can do this permanelty by updating the ~/.ssh/config file on linux or C:\\Program Files\\Git\\etc\\ssh\\ssh_config file on windows and adding the following lines :您可以通过更新 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

If you are using windows and this error is happening in tortoise Git or Sourcetree try to generate your keys with puttYGen.如果您使用的是 Windows 并且在 tortoise Git 或 Sourcetree 中发生此错误,请尝试使用 puttYGen 生成您的密钥。 Or create a new key from your existing private key with puttYGen (use the Load option) then save that private key with the extension ppk in a any folder.或者使用 puttYGen 从您现有的私钥创建一个新密钥(使用加载选项),然后将该私钥以扩展名 ppk 保存在任何文件夹中。 After that, add this key (with the extension ppk) in pageant (google to know how is the icon, it must appear in the right bottom corner next to hour) right click and add key.之后,在选美中添加此密钥(带有扩展名ppk)(谷歌知道图标如何,它必须出现在小时旁边的右下角)右键单击并添加密钥。 Try to be sure you setup your tortoise or your sourcetree to use this ppk key.尽量确保你设置你的乌龟或你的源树来使用这个 ppk 密钥。 Tortoise: Setting - Network - ssh client (must be TortoiseGitPLink.exe, if not is in the git tortoise git_home\\bin folder) Source Tree: Tools - Options - SSh client Putty/PLink Tortoise:设置 - 网络 - ssh 客户端(必须是 TortoiseGitPLink.exe,如果不是在 git Tortoise git_home\\bin 文件夹中) 源树:工具 - 选项 - Ssh 客户端 Putty/PLink

If you're using Git Changes from VS 2019 and having the same issue, you can resolve the issue from the client to re-enable the key exchange algorithms.如果您使用的是 VS 2019 中的 Git Changes 并遇到相同问题,您可以从客户端解决该问题以重新启用密钥交换算法。 You can do this permanently by updating the C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\Git\\etc\\ssh file on windows and adding the following lines :您可以通过更新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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM