Search code examples
.netsftppublic-keywinscpwinscp-net

How to get key fingerprint for SFTP from private key?


As I am working on a .NET C# project which uses WinSCP .NET assembly, for SFTP password less connection. By far I have made an UI where we have to provide SSH key fingerprint, paraphrase, and path of .ppk file.

My question is that, is there any way to get "SSH key fingerprint" automatically through code, if the user gives its .ppk file path only?


Solution

  • The .ppk is a key pair of your account and you specify that using the SessionOptions.SshPrivateKeyPath.

    While the host key for SessionOptions.SshHostKeyFingerprint is for key pair of the server (= host). It's not a public key of your key pair.

    These key pairs have nothing in common. You cannot extract one from another.

    For details, see Understanding SSH key pairs.

    See also Where do I get SSH host key fingerprint to authorize the server?


    If you want to allow the user to verify the host key manually, use the Session.ScanFingerprint method to retrieve the fingerprint for verification. Once verified, assign the verified fingerprint to the SessionOptions.SshHostKeyFingerprint.

    For an example, see Implementing SSH host key cache (known hosts).