0%

更新 Git 客户端后连接远程仓库报错

昨天更新了办公本的 Git 客户端,从 2.25 更新到了 2.28 版本,今天从代码库拉取代码时报错了。

报错信息

1
unable to negotiate with *.*.*.*: no matching key exchange methodfound. Their offer: diffie-hellman-group1-sha1, diffie-hellman-group14-sha1

因为 Git 和远程仓库的连接是基于 ssh 的,而 Openssh 项目在 8.2 版本中弃用了 SHA1:https://www.openssh.com/txt/release-8.2,新版的 Git 客户端也默认禁用了基于 SHA1 加密组件。

以下摘自 openssh 8.2 版本的发行说明:

1
2
3
this release removes the "ssh-rsa" (RSA/SHA1) algorithm from those accepted for certificate signatures (i.e. the client and server CASignatureAlgorithms option) and will use the rsa-sha2-512 signature algorithm by default when the ssh-keygen (1) CA signs new certificates.

this release removes diffie-hellman-group14-sha1 from the default key exchange proposal for both the client and server.

新版的 ssh 从默认的密钥交换协议中移除了 diffie-hellman-group14-sha1,报错信息中可以得知服务器端的 Git 仓库使用的是 diffie-hellman-group14-sha1 协议,所以更新 Git 客户端后,会出现服务器和客户端默认的密钥交换协议不一致的情况,因此连接远程仓库时会报错。

解决方案

在用户目录下的 .ssh 文件中,新建 config 文件,添加以下内容

1
KexAlgorithms +diffie-hellman-group14-sha1

再次尝试更新代码,问题已解决。

参考链接

https://developercommunity.visualstudio.com/content/problem/925718/git-access-by-ssh-fails-with-unsupported-key-excha.html