How to get a server's host key using JavaScript in the browser?

Viewed 118

Given the hostname of a server, I want to get its Host/Public key (stored in /etc/ssh/) using JavaScript in the browser.

I am aware that in the command line, we can get a host key using the ssh-keyscan utility. I want to do the same thing using JS (preferably vanilla JS).

1 Answers

A Node.js script could probably do it a few different ways.

  • it could execute the same ssh-keyscan command a human would use, via the built-in child_process module

You would capture the content of stdout and stderr as strings, and then parse those strings manually.

  • if the data you want can be read directly from a file, you could use the file module to read the file contents as a string, which you would then parse manually

Both of those will work using vanilla JS, and would not require that you install any third-party modules.

Note that Node might need special permissions. You might not encounter that difficulty running this on your local workstation, as yourself, but in a security-conscious environment it will probably require special steps.

Related