none
SSH Connection through PPK without password RRS feed

  • Question

  • Can someone help me to establish SSH connection by authenticate via username and privatekey only using the current SSH.NET library. I cannot get the password from the user so this is out of the question.

    am able to establish the ssh connection manually by feeding the .ppk file to Pageant. Now, looking for some solution to make this connection through C#.

    Information is handy with me is "Host , UserName & .ppk file"

    I found below solution through other sources, but this is throwing an expectation - "Invalid Private Key File"

                     var pk = new PrivateKeyFile(privateKeyLocation);
                     var keyFiles = new[] { pk };

                     var methods = new List<AuthenticationMethod>();
                     methods.Add(new PrivateKeyAuthenticationMethod(userName, keyFiles));

                     var con = new ConnectionInfo(hostName, port, userName, methods.ToArray());

    Please help me to resolve this exception or any alternative solution.

    Thanks in advance!

    Thursday, November 22, 2018 8:05 AM

All replies

  • Hi Venkat6332,

    Thank you for posting here.

    For your question, you want to resolve this exception that "Invalid Private Key File".

    My suggestion is to change the format of the key from .ppk to OpenSSH.

    Use PuttyGen to generate and convert the key (Conversion -> export OpenSSH Key).

    So my key path is the following:

    var privateKeyLocation = @"C:\Users\xxx\Desktop\new";


    This new is the form of OpenSSH Key.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 23, 2018 6:24 AM
    Moderator