3

Is there any way to get SFTP server's public key from any Sftp client or by using any tool? I have access (username/password) to connect to production SFTP remote server and I would like to find the public key from any SFTP client or by using any other tool. My intention is to use that public key in Java JSCh library and to connect to the SFTP server.

2

The only correct way is to ask the server administrator to provide you the host key.

If you retrieve the host key remotely yourself, you cannot really trust the key, as you can be under a Man-in-the-middle attack already.


Anyway, the easiest way is to use ssh-keyscan tool:

> ssh-keyscan example.com
# example.com:22 SSH-2.0-OpenSSH_5.3
example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0hVqZOvZ7yWgie9OHdTORJVI5fJJoH1yEGamAd5G3werH0z7e9ybtq1mGUeRkJtea7bzru0ISR0EZ9HIONoGYrDmI7S+BiwpDBUKjva4mAsvzzvsy6Ogy/apkxm6Kbcml8u4wjxaOw3NKzKqeBvR3pc+nQVA+SJUZq8D2XBRd4EDUFXeLzwqwen9G7gSLGB1hJkSuRtGRfOHbLUuCKNR8RV82i3JvlSnAwb3MwN0m3WGdlJA8J+5YAg4e6JgSKrsCObZK7W1R6iuyuH1zA+dtAHyDyYVHB4FnYZPL0hgz2PSb9c+iDEiFcT/lT4/dQ+kRW6DYn66lS8peS8zCJ9CSQ==

If you are on Windows, you can get a Windows build of ssh-keyscan from Win32-OpenSSH project or Git for Windows.


For more options and background information, see my article Where do I get SSH host key fingerprint to authorize the server?

  • can we install this ssh-keyscan tool in windows since I am using windows machine? – user3742125 Nov 30 '17 at 11:34
  • @user3742125 See my updated answer. – Martin Prikryl Nov 30 '17 at 13:15
  • I downloaded win 64 version. But I am getting an error message saying "This program cant start because libcrypto.dll is missing from your computer". Any idea why?? – user3742125 Nov 30 '17 at 14:05
  • libcrypto.dll is in the OpenSSH-Win64.zip along with the ssh-keyscan.exe, make sure you extract that too. – Martin Prikryl Nov 30 '17 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.