简体   繁体   English

Visual Studio 2022 git 错误无法与 {0} 端口 {1} 协商:找不到匹配的主机密钥类型。 他们的提议:ssh-rsa

[英]Visual Studio 2022 git error Unable to negotiate with {0} port {1}: no matching host key type found. Their offer: ssh-rsa

After updating VS 2022 to 17.1.1, I have a problem with Git. I can't comment, for example, fetch or pusl. VS 2022更新到17.1.1后,Git出现问题,无法评论,比如fetch或者pusl。 I get a message我收到一条消息

Fetching from origin Unable to negotiate with {0} port {1}: no matching host key type found.从来源获取无法与 {0} 端口 {1} 协商:找不到匹配的主机密钥类型。 Their offer: ssh-rsa Failed to fetch from the remote repository.他们的报价:ssh-rsa 无法从远程存储库中获取。 See the Output window for more details.有关详细信息,请参阅 Output window。 Error encountered while fetching: Failed to fetch from the remote repository.获取时遇到错误:无法从远程存储库获取。 See the Output window for more details.有关详细信息,请参阅 Output window。

However, on VS 2019 it works fine, and in SourceTree I can make any comments.但是,在 VS 2019 上它运行良好,在 SourceTree 中我可以发表任何评论。 So it's not a problem with buggy ssh-rsa.所以这不是 buggy ssh-rsa 的问题。

How can I solve it?我该如何解决?

This also happened to me today when I upgraded to the latest version in VS 2019 Community Edition (but the IP address and port of the previously configured Git connection appeared for me).我今天在VS 2019社区版升级到最新版本时也出现了这种情况(但是之前配置的Git连接的IP地址和端口给我出现了)。

Visual Studio IDE has an own Git extension. Visual Studio IDE 有自己的 Git 扩展。 Try to search for that instance in the folder hierarchy and under it the ssh configuration file VS2019 Community Edition:尝试在文件夹层次结构中搜索该实例,并在其下找到 ssh 配置文件 VS2019 Community Edition:

%PROGRAMFILES(x86)%\MicrosoftVisualStudio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\etc\ssh\ssh_config

Add this configuration to the end of this file with the appropriate git server hostname or IP address or both separated by space (to enable the deprecated/insecure encryption at client side):将此配置添加到此文件的末尾,使用适当的 git 服务器主机名或 IP 地址或两者以空格分隔(以在客户端启用已弃用/不安全的加密):

Host gitserver.local
  HostkeyAlgorithms +ssh-rsa
  PubkeyAcceptedAlgorithms +ssh-rsa

This was the solution for me.这是我的解决方案。

There may be another solution to upgrade the Git server-side to support more secure encryptions (eg rsa-sha2-256 or 512).可能还有另一种解决方案来升级 Git 服务器端以支持更安全的加密(例如 rsa-sha2-256 或 512)。

A bit old, but for completeness.有点旧,但为了完整性。

If you update VS 2022 you have to add the lines to the ssh_config file again.如果更新 VS 2022,则必须再次将这些行添加到 ssh_config 文件。

To prevent that, just use another keytype:为防止这种情况,只需使用另一种键类型:

  • generate new key via: ssh-keygen -t ed25519 -C "your_email"通过以下方式生成新密钥: ssh-keygen -t ed25519 -C "your_email"
  • take the content of id_ed25519.pub and add to you git account profile (we use bitbucket)把id_ed25519.pub的内容加到你的git账户资料里(我们用的是bitbucket)
  • you may have to add the id_ed25519 and id_ed25519.pub to the.ssh folder您可能必须将 id_ed25519 和 id_ed25519.pub 添加到 .ssh 文件夹

everything works like a charm一切都像一个魅力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM