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

  1. Jason Yang Xiong using Internet Explorer 8.0 on Windows 7 | January 7, 2014 at 2:01 pm | Permalink

    Regarding how to apply the salt/key to get the hostname hash value, the following is an example.

    This is an entry in ~/.ssh/known_hosts file.
    |1|F1E1KeoE/eEWhi10WpGv4OdiO6Y=|3988QV0VE8wmZL7suNrYQLITLCg= ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgwCZx9lGaY+Zhz98TdWqZ01mTzOwRnQO0EIBM8Hx8olxMbrQ1Xa+x/7LBoGyJqeYFunZbFCVpAu+2SBkvf75qV8nTlq3WXnLnprsH5Sq/c9f29ZCcMHevI

    The host name is
    The following is how to apply the salt/key to get the hashed host name:
    $hex_key=$(echo $(echo F1E1KeoE/eEWhi10WpGv4OdiO6Y= | base64 -d | xxd -p));echo $(echo -n | openssl sha1 -mac HMAC -macopt hexkey:$hex_key)|awk '{print $2}'|xxd -r -p|base64

    So, 3988.....Cg= is the hashed value of

  2. Derek Smalsl using Google Chrome 29.0.1547.76 on Windows 7 | June 14, 2014 at 12:18 pm | Permalink

    "I don't expect you to follow this post completely, but it's so amazingly cool, I have to blog it." - and the award for most arrogant sentence of the day goes to....YOU!!!!

Post a Comment

Your email is never published nor shared.