6

I wish to connect visual studio (2022) to my laptop for cross compilation of c++ projects. I am having an issue however. It doesn't accept the connection.

I have read on another question, that visual studio accepts rsa keys only in PEM format, so I generated the key in that format using ssh-keygen -m PEM -t rsa -b 4096. I have tried with, and without pem format all kinds of different key sizes (1024, 2048, 4096, 8192) with and without passphrases. I have tested each one of those keys by adding the public key to my authorized keys file on my ubuntu laptop and connection from WSL2 using the generated key (ssh -i <key_file> user@host). It worked every time.

I have also read on this question that you should generate the key using puttygen and then exporting the openssh key. I tried that also, with and without passphrases, though only with the default key size. Again connecting from the bash terminal from WSL2 works fine using those keys, but I can't connect in MSVS.

The error messages from visual studio's connection manager make no sense either. When I click connect, it asks me to confirm the fingerprint of the host, and to add it to the known hosts file. When I click yes, the input fields for the connection manager turn red. Hovering over the red fields yiels the results:

For "Host name:" as well as "Port:"

Failed to negotiate host key algorithm. Only RSA and DSA host keys are supported.

I'm not quite sure what that means. My host has an rsa key file formats in their home/.ssh directory. Visual studio says when first connecting that the key fingerprint is "ecdsa-sha2-nistp256", which is supported according to the documentation.

For "Private key file:"

An error occurred connecting using private key '<path to key>'.

When using a key with an empty passphrase before, the passphrase was also marked red, now that indication is gone.

What needs to be done to make it work?

enter image description here

2
  • 2
    It's frustrating how little documentation there is on this, zero error messages, zero logs to check. Microsoft is such a joke at this point. I've spent hours on this exact problem with no movement forward. Commented Dec 22, 2022 at 5:51
  • I currently have this issue, @FalcoGer have you had a chance to find a fix? Visual studio only refuses to connect and puts all input boxes in red, even if they are obviously good without any clear error message. This is tiresome.
    – Shuryno
    Commented Sep 19, 2023 at 12:37

2 Answers 2

2

I had a similar problem, in my case I was trying to connect into a ubuntu server.

Checking the sshd service status (systemctl status ssh) while I trying to connect with visual studio, I got this error:

userauth_pubkey: signature algorithm ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]

Then I added this line PubkeyAcceptedAlgorithms +ssh-rsa into the /etc/ssh/sshd_config file, then restarted the sshd service (in the server machine)

After that change, I was able to connect into the server with the Visual Studio.

Some references:

1

If using ssh-keygen to create the private key, you must specify the switch -m pem, or the key will not be accepted by Visual Studio. If your private key begins with -----BEGIN OPENSSH PRIVATE KEY-----, you must convert it with ssh-keygen -p -f -m pem.

https://learn.microsoft.com/en-us/cpp/linux/connect-to-your-remote-linux-computer?view=msvc-170

1
  • Thanks! This is actually what was causing a connection problem for me as well.
    – xoofx
    Commented Jun 7 at 13:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .