Visual Studio remote SSH does not connect with key


I’m trying to setup remote debugging in Visual Studio (not VS Code!) using key-based SSH connection.

It fails at the first step of adding new connection in Connect to Remote System dialog.

I have verified the following:

  • The private key is in PEM format (begins with -----BEGIN RSA PRIVATE KEY-----).

  • The SSH login works in terminal and uses the provided PEM key and not password via ssh -v -i id_rsa user@host_ip.

  • The same target can be debugged from Visual Studio via password-based SSH so in general remote debugging works.

When I add the connection and press Connect button I get Connectivity failure error and Cross Platform Logging produces the following trace:

    10:52:20.2991235 [Info, Thread 1]   liblinux.RemoteSystemBase: Connecting over SSH to 192.168.20.2:22
    10:52:20.4114885 [Info, Thread 36]  liblinux.HostKeyVerifier: Connection failed.
    10:52:20.4114885 [Info, Thread 36]  liblinux.HostKeyVerifier: System.Security.Cryptography.CryptographicException: Specified padding mode is not valid for this algorithm.
    at System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
    at System.Security.Cryptography.RSA.SignData(Byte[] data, Int32 offset, Int32 count, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
    at System.Security.Cryptography.RSA.SignData(Byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
    at Renci.SshNet.Security.KeyHostAlgorithm.Sign(Byte[] data)
    at Renci.SshNet.PrivateKeyAuthenticationMethod.Authenticate(Session session)
    at Renci.SshNet.ClientAuthentication.TryAuthenticate(ISession session, AuthenticationState authenticationState, String[] allowedAuthenticationMethods, SshAuthenticationException& authenticationException)
    at Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
    at Renci.SshNet.ConnectionInfo.Authenticate(ISession session, IServiceFactory serviceFactory)
    at Renci.SshNet.Session.<ConnectAsync>d__180.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Renci.SshNet.BaseClient.<CreateAndConnectSessionAsync>d__56.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Renci.SshNet.BaseClient.<ConnectAsync>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at liblinux.HostKeyVerifier.<ConnectAsync>d__24.MoveNext()
    10:52:20.4114885 [Error, Thread 36] liblinux.RemoteSystemBase: Connection failure over SSH to 192.168.20.2:22
    10:52:20.4114885 [Error, Thread 36] liblinux.RemoteSystemBase: System.Security.Cryptography.CryptographicException: Specified padding mode is not valid for this algorithm.
    at System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
    at System.Security.Cryptography.RSA.SignData(Byte[] data, Int32 offset, Int32 count, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
    at System.Security.Cryptography.RSA.SignData(Byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
    at Renci.SshNet.Security.KeyHostAlgorithm.Sign(Byte[] data)
    at Renci.SshNet.PrivateKeyAuthenticationMethod.Authenticate(Session session)
    at Renci.SshNet.ClientAuthentication.TryAuthenticate(ISession session, AuthenticationState authenticationState, String[] allowedAuthenticationMethods, SshAuthenticationException& authenticationException)
    at Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
    at Renci.SshNet.ConnectionInfo.Authenticate(ISession session, IServiceFactory serviceFactory)
    at Renci.SshNet.Session.<ConnectAsync>d__180.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Renci.SshNet.BaseClient.<CreateAndConnectSessionAsync>d__56.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Renci.SshNet.BaseClient.<ConnectAsync>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at liblinux.HostKeyVerifier.<ConnectAsync>d__24.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at liblinux.HostKeyVerifier.<ConnectAsync>d__24.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at liblinux.RemoteSystemBase.<ConnectCoreAsync>d__68.MoveNext()

Leave a Reply

Your email address will not be published. Required fields are marked *