Image of the glider from the Game of Life by John Conway
Skip to content

Making Sense of Hashed Hosts in ~/.ssh/known_hosts

I don't expect you to follow this post completely, but it's so amazingly cool, I have to blog it. Consider the hashed sections of ~/.ssh/known_hosts file for (recent) OpenSSH clients, not including the public key parts:


The column fields are similar to that of the /etc/shadow file on GNU systems, except where the "$" is the column delimiter, "|" is in this case. If the string was "|1|o6FFoirXYblM7wBMdeJDYGMPI58=|5jJB7T7itY702ZHHByXtSpGk9SE=", then the breakdown is as follows:

  • |1- HASH_MAGIC. This tells the client that the host information has been salted and hashed with the SHA1 algorithm.
  • |o6FFoirXYblM7wBMdeJDYGMPI58= This is the salt applied to the host- base 64 encoded 160-bit string.
  • |5jJB7T7itY702ZHHByXtSpGk9SE= This is the base 64 encoded version of the hashed host

Now, if you want to get at the actual strings, not base 64 encoded, you could run the following command (I admit, not elegant, and could probably be better solved without nesting, and a single awk(1) statement, but I'll get to that later):

% echo $(echo o6FFoirXYblM7wBMdeJDYGMPI58= | openssl base64 -d | xxd | cut -c 10-48) | sed 's/ //g'
% echo $(echo 5jJB7T7itY702ZHHByXtSpGk9SE= | openssl base64 -d | xxd | cut -c 10-48) | sed 's/ //g'

There you have it. Very cool. Now, the only question is how to apply the salt to the hostname, to get to the hash? I'm working that out, but I wasn't motivated enough to get to it. Of course, there's no application to this, that I can tell, unless you want to brute force the known_hosts file.

{ 2 } Comments