In cases like this I use the following little script (tested on Debian and Ubuntu):
#!/bin/sh
# Gather the public ssh host keys for the given host
# and for each key print the fingerprint in hex format using the given
# checksum command (e.g. md5sum, sha256sum, ...)
if [ "$#" != 2 ]; then
echo "usage: $0 hostname checksum_command"
exit 1
fi
ssh-keyscan $1 2>/dev/null | while read -r line; do
echo "Scanned key:"
echo $line
echo "$2 fingerprint:"
echo $line | awk '{print $3}' | base64 -d | $2 -b | awk '{print $1}' | sed 's/../&:/g' | sed 's/:$//'
echo
done
Example usage:
$ myscript host.example.com md5sum
Scanned key:
host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJUXq7vpcEpnZQxxiLw/tdg8ui4LoqbW1O5nGyLtGw49
md5sum fingerprint:
6c:ef:26:f7:98:ad:ed:5b:cc:ff:83:13:46:c9:f6:79
Scanned key:
host.example.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC4aLMajBvisnWNR2VX5K1KEkNeRmzlcs+svbY6/DiumMTZNtqB5duZjGkMmEbIclHaT7rQG9efAWsNhai5cJVRZ4VX1Gu/TLycEk4OY56MrrWjQYweSUr/W6E0eVCf7gh/ym2vMcevct4373fGDdlogk9Wa97lDV6PUXRy/znxRlo3tBc6KMOZIBoPu8UjeLr2ZPNPjO6hXX/96HbYfboxjhMl5eb8AWR0MGd4qU7RZZa2XhT4/4eSo8h9gEq8V3tasB24fMdw3K+HRiDyZm8uoNq+IrJlC22pBpzxRQtsv0Nd+uC5pK/UPVI3AFfdHMrmn7IHRio8aEaTloM6MRysGMtXE0kFQ/pV2U3TBmK/9wxID83qMDsQeUH4oTyjSJ0dCBuqgVQUg44z5qXVOK7gruvZSTyH7DsIyAXhlvLNwdtXPJ4HPQ90ZxLpiFWYgSPErQgbfgKeFkoSQiSP1M+UMkITCGRKMeUeDINheRJh/5y8+C3DjE54xyI4903ztyI7HqgVTOOFCtf+dlhCuS6+J20PFXEHDMdGCwmPQrKOG9Rb4NBxuvtn7MxJnwnlIu3nhDjr8SlZDOTvuK+bLpc4AZwEsNY7ANKFvj2mqE6hjkhu+x7khg84VQ6BKOmHIQnMrCpqICaNgB7Vz2d183BETrnfKQaPh79G5cQox5vwvw==
md5sum fingerprint:
b2:9c:cd:30:b1:38:e3:d1:17:d6:73:eb:03:9a:80:83
$ myscript host.example.com sha256sum
Scanned key:
host.example.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC4aLMajBvisnWNR2VX5K1KEkNeRmzlcs+svbY6/DiumMTZNtqB5duZjGkMmEbIclHaT7rQG9efAWsNhai5cJVRZ4VX1Gu/TLycEk4OY56MrrWjQYweSUr/W6E0eVCf7gh/ym2vMcevct4373fGDdlogk9Wa97lDV6PUXRy/znxRlo3tBc6KMOZIBoPu8UjeLr2ZPNPjO6hXX/96HbYfboxjhMl5eb8AWR0MGd4qU7RZZa2XhT4/4eSo8h9gEq8V3tasB24fMdw3K+HRiDyZm8uoNq+IrJlC22pBpzxRQtsv0Nd+uC5pK/UPVI3AFfdHMrmn7IHRio8aEaTloM6MRysGMtXE0kFQ/pV2U3TBmK/9wxID83qMDsQeUH4oTyjSJ0dCBuqgVQUg44z5qXVOK7gruvZSTyH7DsIyAXhlvLNwdtXPJ4HPQ90ZxLpiFWYgSPErQgbfgKeFkoSQiSP1M+UMkITCGRKMeUeDINheRJh/5y8+C3DjE54xyI4903ztyI7HqgVTOOFCtf+dlhCuS6+J20PFXEHDMdGCwmPQrKOG9Rb4NBxuvtn7MxJnwnlIu3nhDjr8SlZDOTvuK+bLpc4AZwEsNY7ANKFvj2mqE6hjkhu+x7khg84VQ6BKOmHIQnMrCpqICaNgB7Vz2d183BETrnfKQaPh79G5cQox5vwvw==
sha256sum fingerprint:
f4:61:58:e4:90:65:c4:70:98:7f:d1:40:0a:d8:d9:79:14:e6:91:dc:b6:ed:91:8c:c0:df:d9:65:db:dd:a0:18
Scanned key:
host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJUXq7vpcEpnZQxxiLw/tdg8ui4LoqbW1O5nGyLtGw49
sha256sum fingerprint:
4b:73:d1:d7:80:87:46:64:56:71:64:10:7a:66:83:9b:c7:58:39:0b:16:74:dd:9b:d9:4b:e5:d5:61:7e:99:45
1Unfortunately, this does not work. My question contains the result of running your suggested command. Newer versions of ssh-keygen give the md5 hash as a (base64 encoded?) string instead of a hex string. "All that harakiri" (an apt description!) is the easiest way i could find to get an old style hex string from the new version of openssh tools. – stochastic – 2016-06-12T12:47:29.727
Unless FreeBSD break something (or removed MD5 support), there is no reason why it should not work. Note that your command lists wrongly
sha1
instead ofmd5
! I have outdated Ubuntu version with openssh-6.9, but it works just fine. – Jakuje – 2016-06-12T13:17:04.0531md5 instead of sha1... not sure how I missed that. That does indeed give matching output. – stochastic – 2016-06-12T13:21:00.817
I have the opposite problem. I have the md5 and want the other format. How do I get it? – Gabriel Staples – 2017-08-03T19:05:59.650
1Works when command is executed on ubuntu. Does not work when command is executed on centos. – Marinos An – 2017-12-12T11:36:51.637
@MarinosAn it depends on which version. CentOS 6 is old and you will get this output by default, CentOS 7 should work this way already. – Jakuje – 2017-12-12T11:42:07.230