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 Please make sure you have the correct access rights |
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,回车即可。