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

VS 2022 更新到 17.1.1 后,Git 出现问题。我无法评论,例如,fetch 或 pusl。我收到一条消息

Fetching from origin Unable to negotiate with {0} port {1}: no matching host key type found. Their offer: ssh-rsa Failed to fetch from the remote repository. See the Output window for more details. Error encountered while fetching: Failed to fetch from the remote repository. See the Output window for more details.

但是,在 VS 2019 上它运行良好,在 SourceTree 中我可以发表任何评论。所以这不是 buggy ssh-rsa 的问题。

我该如何解决?

我今天在VS 2019社区版升级到最新版本时也出现了这种情况(但是我之前配置的Git连接的IP地址和端口出现了)。

Visual Studio IDE 有自己的 Git 扩展名。尝试在文件夹层次结构中搜索该实例,并在其下搜索 ssh 配置文件 VS2019 社区版:

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

使用适当的 git 服务器主机名或 IP 地址将此配置添加到此文件的末尾 或两者用 space 分隔(以在客户端启用 deprecated/insecure 加密):

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

这就是我的解决方案。

可能还有另一种解决方案来升级 Git server-side 以支持更安全的加密(例如 rsa-sha2-256 或 512)。

有点旧,但为了完整性。

如果更新 VS 2022,则必须再次将行添加到 ssh_config 文件。

为了防止这种情况,只需使用另一个键类型:

  • 通过以下方式生成新密钥:ssh-keygen -t ed25519 -C "your_email"
  • 取id_ed25519.pub的内容添加到你的git账户资料(我们用的是bitbucket)
  • 您可能需要将 id_ed25519 和 id_ed25519.pub 添加到 .ssh 文件夹

一切都很顺利