Git异常 #Unable to negotiate with xx.xx.xx.xx port 29418: no matching key exchange method found.

本文解决了一种常见的Git操作问题,当新安装Git后,在拉取代码时出现无法协商密钥交换方法的错误。通过修改.ssh配置文件,指定支持的密钥交换算法,成功解决了该问题。

1.异常现象

换机新安装 Git 后,拉代码时出现问题:

Unable to negotiate with 10.18.18.18 port 29418: no matching key exchange method found. Their offer: diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

2.排查分析

从字面上理解,git 服务器端支持 diffie-hellman-group1-sha1 这种密钥交换方法,而 git 客户端不支持。

3.解决方案

跳到 .ssh 目录:

cd ~/.ssh

在C盘 “用户/当前用户名/.ssh/” 目录下新建一个 config 文件,无扩展名。然后使用写字板等工具打开,输入并保存以下内容:

Host *
KexAlgorithms +diffie-hellman-group1-sha1

或者,输入并保存以下内容(于2022年12月27日更新,感谢 qq_43255910 补充):

Host *
PubkeyAcceptedKeyTypes +ssh-rsa
HostKeyAlgorithms +ssh-rsa

 

如此,即好。
不防再试一下刚刚没有执行成功的 git clone 命令。

如果有遇到提示:Are you sure you want to continue connecting (yes/no/[fingerprint])? 
输入 yes,回车即可。

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值