Parliament Hill Computers LtdParliament Hill Computers Ltd

Checking ssh public key fingerprints


Index

What is this all about ?

Summary: increasing security by verifying the identity of the machine that you connect to with ssh by eye and with SSHFP in DNS.

ssh allows you to connect to a remote machine with the data between the two machines being encrypted. You can then securely do: command line login, file copy, tunnel other protocols (eg: rsync, X11), ... You authenticate by either typing a password or key exchange.

A big vulnerability is a man in the middle attack where some malevolent snooping entity (Mallory) between you and the remote machine intercepts all traffic, decrypts it & reencrypts before sending it on. Mallory can do this fast enough so that you are not aware of his existance.

To protect you against this your ssh program checks the remote ssh server's fingerprint with the fingerprint saved from the last time it connected. If the fingerprint has changed you will be warned and asked if you wish to continue. In openssh (the ssh used on most Linux systems) this fingerprint is stored in $HOME/.ssh/known_hosts.

The fingerprint is a short version of the server's public key; it is easier for you to verify than the full key. It is very hard to spoof another public key with the same fingerprint.

The problem

When you connect to a machine for the first time you do not have the fingerprint in your known_hosts, so ssh has nothing to compare it to, so it asks you. This page describes ways in which you can do more than blindly say yes.

Checking a ssh server key fingerprint by eye

When you connect to a machine for the first time you will be told that the authenticity can't be established and presented with a key fingerprint to check. Something like this:

The authenticity of host 'mint.phcomp.co.uk (78.32.209.33)' can't be established.
RSA key fingerprint is 6a:de:e0:af:56:f8:0c:04:11:5b:ef:4d:49:ad:09:23.
Are you sure you want to continue connecting (yes/no)? no

You might find that the fingerprint is shown in a different format — just keep reading.

To be able to check the fingerprint you need to know what it is. You will probably find the .pub files in /etc/ssh/ that contain RSA & DSA keys. This will generate the fingerprints that you can check:

cd /etc/ssh
for file in *sa_key.pub
do   ssh-keygen -lf $file
done

There is little point in doing this after you have logged in, a sufficiently ingenious Mallory could modify what the above generates on the fly so that you see what he wants you to see. This needs to be done before hand and you can then check it with what you see. You might print the fingerprints out and keep them in your briefcase or wallet.

Displaying fingerprints in other formats

You might find that the fingerprint is generated in a different format from what you have. This section tells you how, when connecting, you get the ssh client to show them in different formats and, on the server, have ssh-keygen generate different format references.

You may need to mix and match depending on what you have in front of you and where you are able to run commands.

Forcing MD5 hash in hexadecimal

This is the format shown above. You can force ssh to display this thus:

 $ ssh -o FingerprintHash=md5 host.example.org

SHA256 in base64

This new format looks as below:

The authenticity of host 'mint.phcomp.co.uk (78.32.209.33)' can't be established.
RSA key fingerprint is SHA256:jP0pfKJ9OAXt2F+LM7j3+BMalQ/2Koihl5eH/kli6A4.
Are you sure you want to continue connecting (yes/no)? 

You can request this with:

 $ ssh -o FingerprintHash=sha256 host.example.org

You can get ssh-keygen to display it:

  ssh-keygen -l -E sha256 -f $file


This is used in OpenSSH 6.8 & later. The FingerprintHash is not available in old versions.

ASCII Art Visual Host Key

This displays the host key in a box and is, hopefully, easier to recognise than a string of numbers. It can be used to display both MD5 and SHA256 keys. It looks like this:

The authenticity of host 'mint.phcomp.co.uk (78.32.209.33)' can't be established.
RSA key fingerprint is SHA256:jP0pfKJ9OAXt2F+LM7j3+BMalQ/2Koihl5eH/kli6A4.
+---[RSA 2048]----+
|                 |
|                 |
|         .     . |
|       +. .   =  |
|      . S=   o + |
|       .oo+.. o o|
|      E.=***.= + |
|      .=*=BoXo+  |
|      .o+=o=+*o. |
+----[SHA256]-----+
Are you sure you want to continue connecting (yes/no)? 

You can request ssh to display it thus:

 $ ssh -o VisualHostKey=yes host.example.org

You can request MD5 or SHA256 keys, eg:

 $ ssh -o VisualHostKey=yes -o FingerprintHash=sha256 host.example.org

On the server ssh-keygen will display when given the -v option. Combine this with -E md5 or -E sha256 for the fingerprint hash algorithm:

  ssh-keygen -lv -E sha256 -f $file

Checking of a ssh server key via DNS

You can put the server keys fingerprint in DNS (Domain Name System) and get ssh to tell you if what it the two fingerprints match. This is not a guarantee but it makes Mallory's job harder since he needs to spoof DNS as well as ssh, which can be done as few domains yet implement DNSSEC.

Configuring DNS

Using the DNS SSHFP RR

Other things of interest

References

Technical bits

You don't really need to understand this bit to use the above; however if you are a technical nerd you will want to know.

Thanks

Thanks to Katie Foster <Katie.Foster@auspost.com.au> for reporting an error in a previous version of this page.

License and copyright

All description & sample files copyright (c) 2012, 2016 Parliament Hill Computers. Author: Alain D D Williams.

You may used these files as the basis your own (or organisation's/company's) project(s) (under whatever licence that you see fit). You may not claim ownership or copyright of any substantially unmodified files. Acknowledgement would be appreciated, but is not necessary.

These demonstrations are made available in the hope that they are useful. There may be errors: there is no warranty at all, use at your own risk.

Return to tutorial home.

If you want any help using the above, or have any comments or suggestions, please contact us.