Accept Host Key Automatically?

Mar 11, 2013 at 5:21 PM

I am using this library within a .net application to connect to an SFTP server. It has been running for about a year without issue, and still is. I connect to the server through an automated process that requires no intervention.

The administrator of the SFTP server is changing the host key and has notified users that we need to accept the host key. I never had to accept the host key in the first place when I was initially connecting, so my instinct is that I don't need to do anything to accept the new one.

I don't do anything with the HostKeyReceived event, and I see that the default value of CanTrust in HostKeyEventArgs is true.

Does that mean that I am correct, that the new Host Key will be trusted by default?

Mar 11, 2013 at 7:33 PM
Hi Chip,

Yes, this is correct. By default it accepts all host keys.

The only time you want to use HostKeyReceived event if you want to add some logic and manually to approve or deny host.

Mar 12, 2013 at 1:47 PM

That's great... thank you for confirming this and for your quick response!

Feb 3 at 4:30 AM
If the administrator provided you a host key, then you should only proceed with the connection if the host key matches. See this post for how to: