Visual Studio 2022 git error Unable to negotiate with xx.xxx.xxxx port 22: no matching host key type found. Their offer: ssh-rsa


前言

  前兩天因為升級了Git導致git提交拉取的時候都提示下面這個異常,然后經過一番折騰以后終於把這個問題解決了。但是今天我升級了下Visual Studio 2022將其升級到了17.1.3版本然后又出現了這個問題,奇怪的是我使用VS 2019沒有問題(VS2019沒有升級),然后使用Git Bash也是可以正常拉取提交。唯獨使用VS 2022就提示下面的異常(真的是問題天天有,四月特別多):

Unable to negotiate with xx.xxx.xxxx port 22: no matching host key type found. Their offer: ssh-rsa
Git failed with a fatal error.
Git failed with a fatal error.
Could not read from remote repository.
 
Please make sure you have the correct access rights
and the repository exists. 

vs 2022版本

問題分析

因為Visual Studio IDE有自己的Git擴展,既然我們設置了Git在C盤中的.SSH目錄中的config配置無效,那會不會在VS 2022里面也會有一個類型於這樣的配置呢?於是我搜索了一下果然讓我發現了端倪。

vs2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\etc\ssh

如下是我對比VS2019和VS2022的配置:

解決方案一,切換成HTTPS的方式

1、修改本地代碼關聯的遠程地址

git remote set-url origin https://gitee.com/ysgdaydayup/pingrixuexilianxi.git

2、重新拉取成功 

git pulll

解決方案二,在ssh_config配置文件中添加對應主機地址配置

我們其實直接Copy一下VS2022新增現有配置,然后修改一下主機地址就可以了(注意添加好配置以后一定要重啟一下VS 2022才會生效)。

1、該配置指的是對所有主機生效

Host *
     HostkeyAlgorithms +ssh-rsa
     PubkeyAcceptedAlgorithms +ssh-rsa

2、指定對應主機生效(xx.xxx.xxxx:22)

Host xx.xxx.xxxx:22
       HostkeyAlgorithms +ssh-rsa
       PubkeyAcceptedAlgorithms +ssh-rsa

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM