13

I have a .NET 5 application running on a Debian server that I would like to attach a debugger to. The debugger I am trying to use is the one integrated into Visual Studio 2019.

I meet all the prerequisites listed in the documentation.

When setting up a new connection, a password connection works. However, none of my attempts with a private key result in a usable connection.

This private key works well when connecting via both PuTTY and the Windows OpenSSH binary outside of Visual Studio. Therefore, the underlying SSH tooling appears to be set up correctly.


Attempts:

  • Unprotected OpenSSH-compatible private key:

    Results in a %LocalAppData%\devenv_exe_linux_connection_error_133651_090121.log containing just the text Bad Data.

    Also says Passphrase invalid on the empty passphrase box

  • Password-protected OpenSSH-compatible private key:

    Exactly the same result as the unprotected key. Bad Data. and Passphrase invalid.

  • Unprotected PuTTY-compatible private key:

    Host/port textboxes report Failed to negotiate host key algorithm. Only RSA and DSA host keys are supported. (server has ecdsa/ed25519/rsa host keys available, also the ecdsa host key was accepted by password auth)

    Private key file textbox reports An error occurred connecting using private key ...

    Empty passphrase textbox reports Passphrase invalid

  • Password-protected PuTTY-compatible private key:

    Exactly the same result as the unprotected key. Failed to negotiate host key algorithm. / An error occurred connecting using private key / Passphrase invalid.

At this point it's unclear what key format Visual Studio supports, as I have tried all the common ones.

Ideally I'd like to use the key I have stored in Pageant-compatible KeeAgent, also exposed via an OpenSSH-compatible socket. But I'll settle for getting a private key via file working.


Versions:

  • Visual Studio 2019 Professional, Version 16.11.2
  • dotnet SDK 5.0.101 on Debian Buster

3 Answers 3

8

What worked for me connecting to a dot net core 2.1 process on Linux was this:

  • open puttygen, load the putty private key
  • specify a passphrase to export the key
  • In the Conversions menu, choose Export OpenSSH key

Then, in Visual Studio 2019:

  • go to Tools / Options / Cross platform / connection manager
  • add a new connection
  • set the hostname, port and username.
  • for Auth type, select private key and then select the file exported above as the private key. Set the passphrase you used before.
  • Click the Connect button, it should print something like "connection verified"
  • Close options

Then in the attach to process dialog, Connection type = SSH and select the Connection target you just configured, it should be able to show the remote processes and let you attach.

3
  • Nice guess but not helpful. This is VS2019 not Linux.
    – Bob Denny
    Commented May 28, 2022 at 18:30
  • Seriously? Are you reading the answer? It's all Windows and VS2019. Commented May 29, 2022 at 19:08
  • 1
    Yeah, I finally figured out that VS2019 takes an old-fashioned PEM key. I already had the key in OpenSSH format from ssh-keygen. It turned out that a super-obscure command line option in ssh-keygen does an IN-PLACE conversion of an OpenSSH pubkey to a PEM pubkey (watch out it wipes out your OpenSSH key so do it to a copy!). ssh-keygen -f id_rsa -e -m pem Now id_rsa is in PEM format. The name can be anything really.
    – Bob Denny
    Commented May 30, 2022 at 23:36
2

This what worked for me :

1 - Create private key in power-shell and add passphrase with command-line :

ssh-keygen -t rsa -b 4096

3 - Open PuTTYgen, load your private key then go to Conversions->Export OpenSSH and export your private key

1

According to microsoft:

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

Versions of Visual Studio before 17.10 support EC, RSA, and DSA keys for remote connections. Because of security concerns, RSA and DSA keys are no longer supported in VS 17.10 and later. Only EC keys are currently supported. To create a key pair compatible with the connection manager use the command: ssh-keygen -m pem -t ecdsa -f

These days only elliptic curve keys are allowed, just got it working with ssh-keygen -t ecdsa ....

Not the answer you're looking for? Browse other questions tagged or ask your own question.