問題描述
今天升級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
1
方案二
在.ssh目錄下面新建一個config文件並在config文件中添加以下代碼
Host xx.xx.x.xxx
KexAlgorithms +diffie-hellman-group1-sha1
其中 xx.xx.x.xxx爲服務器的ip地址或者域名
比較
個人覺得方案二好一些,也是目前我目前採用的方案