问题描述
今天升级Ubuntu系统到16.04之后,之前通过git管理的一个项目add和commit之后无法push到服务器。每次提交都报以下错误:
Unable to negotiate with xx.xx.x.xxx port xxxx: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
分析之后发现是git server和client使用的ssh key解析算法不一致造成的,client因为系统升级的原因默认使用新的key exchange method而服务器只提供diffie-hellman-group1-sha1方法,因此无法正常建立链接。
解决方案
解决方案有以下两个
方案一
在project directory/.git/config文件中的ssh 后面添加下面这段代码
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1
方案二
在.ssh目录下面新建一个config文件并在config文件中添加以下代码
Host xx.xx.x.xxx
KexAlgorithms +diffie-hellman-group1-sha1
其中 xx.xx.x.xxx为服务器的ip地址或者域名
比较
个人觉得方案二好一些,也是目前我目前采用的方案