'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. I get a message

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.

However, on VS 2019 it works fine, and in SourceTree I can make any comments. So it's not a problem with buggy ssh-rsa.

How can I solve it?



Solution 1:[1]

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).

Visual Studio IDE has an own Git extension. Try to search for that instance in the folder hierarchy and under it the ssh configuration file 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):

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 (e.g. rsa-sha2-256 or 512).

Solution 2:[2]

A bit old, but for completeness.

If you update VS 2022 you have to add the lines to the ssh_config file again.

To prevent that, just use another keytype:

  • generate new key via: ssh-keygen -t ed25519 -C "your_email"
  • take the content of id_ed25519.pub and add to you git account profile (we use bitbucket)
  • you may have to add the id_ed25519 and id_ed25519.pub to the .ssh folder

everything works like a charm

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tijko
Solution 2 David