SSH connection to a database using a tunnel

Nelson Soares 0 Reputation points
2025-04-03T15:36:37.5533333+00:00

I´m trying to connect to a postgres db through an ssh tunnel.

I´m using the following code:

       

But i´m allaways getting the error "Invalid private key". I´ve already using putty gen load key-> Export open ssh key but i got allaways the same key format and the same error (Invalid private key).

Can you please helP ??

the code above i´ve tryed. i hope to get the right key to connect correctly trough the tunnel

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2025-04-04T05:44:05.21+00:00

    Hi @Nelson Soares ,

    Please check the SSH.Net usage documentation. https://github.com/sshnet/SSH.NET

    Renci.SshNet only supports OpenSSH format private keys, you seem to be using a public key. First you'd better test whether your key is correct. Run the OpenSSH ssh command in Windows (with OpenSSH), Mac or Linux terminal to see if the connection is successful or the reason for the error.

    If the key is fine, modify it to the format supported by Renci.SshNet according to the documentation.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.