git 克隆git存储库的问题

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

Issue with cloning git repository

gitssh

提问by debonair

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/configand 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 [email protected] -p 2222but I am getting connection refused with port no 22 as well.

其他解决方案是使用该命令,ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 [email protected] -p 2222但我的连接也被拒绝,端口号为 22。

I am using windows machine.

我正在使用 Windows 机器。

采纳答案by CodeWizard

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:
Unable to negotiate with 127.0.0.1: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

如果客户端和服务器无法就一组相互的参数达成一致,则连接将失败。
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.

现在在您的服务器帐户下添加公钥并重试。

回答by suiwenfeng

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
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.

回答by Venu Gopal Tewari

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 文件。

回答by yao

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/configwill make the clone running as the current user works.

进入~/.ssh/config将使克隆在当前用户工作时运行。

For other users, the OpenSSH won't pick up the config. I have to add the above config into the global config file: "C:\Program Files\Git\etc\ssh\ssh_config"to make it work.

对于其他用户,OpenSSH 不会选择配置。我必须将上述配置添加到全局配置文件中: “C:\Program Files\Git\etc\ssh\ssh_config”才能使其工作。

回答by chaosifier

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/configfile on linux or C:\Program Files\Git\etc\ssh\ssh_configfile 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

回答by Mayur Chavan

Appending the file C:\Program Files\Git\etc\ssh\ssh_configwith below content worked for me:

使用以下内容附加文件C:\Program Files\Git\etc\ssh\ssh_config对我有用

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

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

( Cheers )

(干杯)

回答by Jva Dev

If you are using windows and this error is happening in tortoise Git or Sourcetree try to generate your keys with 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. 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. Try to be sure you setup your tortoise or your sourcetree to use this ppk key. 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

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