Skip to content

Instantly share code, notes, and snippets.

@redmcg
Last active January 17, 2020 06:29
Show Gist options
  • Save redmcg/571bc4f1f67aeb1cf016af278205c12f to your computer and use it in GitHub Desktop.
Save redmcg/571bc4f1f67aeb1cf016af278205c12f to your computer and use it in GitHub Desktop.
An awk script that provides the same functionality as ssh-keygen -F <host>
#!/usr/bin/env bash
host=$1
awk -v host=$host '
/^|1/ {
split($1, a, /\|/)
key=a[3]
hmac=a[4]
"echo -n " host " | openssl sha1 -mac HMAC -macopt hexkey:$(echo " key " | base64 -d | xxd -p) -binary | base64" | getline myhmac
if (hmac == myhmac) {
print "# Host " host " found: line " NR
print
}
}' ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment