0 votes
by (160 points)
edited

Hello,

I am unable to get the SshServer Host key Fingerprint. It is coming as constant value even if i connect to different Ssh servers. Looks like fingerprint property is not working property. can some one plz help me for the same. will appreciate if some can provide the sample codes in c#.

2 Answers

0 votes
by (144k points)
edited

I just tried running the following simple console app that connects to 2 different SSH servers and displays their host key fingerprint:

using System;
using Rebex.Net;

namespace Testing
{
    public class ConsoleApp
        {
        public static void Main()
        {
            Sftp sftp = new Sftp();

            sftp.Connect("sdf.org");
            string fingerprint1 = sftp.Fingerprint;
            Console.WriteLine(fingerprint1);
            sftp.Disconnect();

            sftp.Connect("nuane.com");
            string fingerprint2 = sftp.Fingerprint;
            Console.WriteLine(fingerprint2);
            sftp.Disconnect();
        }
    }
    }

It displays the following output:

13:b9:23:70:a1:e5:e5:30:5a:09:0b:a6:74:03:89:a6
99:42:e4:08:85:0e:50:6c:43:ff:42:34:26:eb:5a:ef

Everything looks OK. Would it be possible to post the code you were using?

0 votes
by (160 points)
edited

Thanks for ur reply Lukas Pokorny..

The problem with my code was, I missed to set the HostKeyAlgorithms property before opening the connection..

I am getting the right keys after writing the below code:

sshSession.Parameters.HostKeyAlgorithms = SshHostKeyAlgorithm.RSA; sshSession.Connect(new IPEndPoint(Dns.GetHostAddresses(hostname)[0], sshPort));

My SshSession code was working fine without setting HostKeyAlgorithms, but the only problem was that, I was not getting the unique fingerprint...

Please let me know if there is any side effect of assigning the HostKeyAlgorithms of SshSession???

by (144k points)
edited

The only side effect is that you won't be able to connect to servers which only use DSS host key and don't have an RSA host key.

A better solution is to set PreferredHostKeyAlgorithm instead of HostKeyAlgorithms:

sshSession.Parameters.PreferredHostKeyAlgorithm = SshHostKeyAlgorithm.RSA;

This will behave just like your code with servers that have both RSA and DSS keys. However, if the server only has a DSS host keys, it will still connect.

...