Skip to content

Instantly share code, notes, and snippets.

@stemid
Last active September 16, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stemid/892fc4d51f13f0241970 to your computer and use it in GitHub Desktop.
Save stemid/892fc4d51f13f0241970 to your computer and use it in GitHub Desktop.
sshfp to generate SSHFP records for ecdsa.
#!/bin/bash
# {{ ansible_managed }}
#
# rewritten from http://blog.chr.istoph.de/dns-sshfp-record-fuer-alle-algorithmen-gleichzeitig-erstellen/
#
# Create SSHFP records from public keys, supports ecdsa too.
# Stefan.Midjich@cygate.se added support for alternate config dirs. 2015-11-16
domain="$1"
config_dir="${2:-/etc/ssh}"
if [ -z "$domain" ]; then
echo "Usage: $0 domain [config_dir]"
exit 0
fi
function sshfp() {
a=$1 #algorithmus
f=$2 #file
echo $domain IN SSHFP $a 1 $(cut -d' ' -f2 $f|base64 -d|sha1sum|cut -d' ' -f1)
echo $domain IN SSHFP $a 2 $(cut -d' ' -f2 $f|base64 -d|sha256sum|cut -d' ' -f1)
}
for f in "$config_dir"/ssh_host_*_key.pub; do
case "$f"
in
*_rsa_key*)
sshfp 1 $f
;;
*_dsa_key*)
sshfp 2 $f
;;
*_ecdsa_key*)
sshfp 3 $f
;;
*_ed25519*)
sshfp 4 $f
;;
esac
done | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment