Skip to content

Instantly share code, notes, and snippets.

@gesquive
Last active July 3, 2019 18:05
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 gesquive/34c882926ee8b671e8366de948622001 to your computer and use it in GitHub Desktop.
Save gesquive/34c882926ee8b671e8366de948622001 to your computer and use it in GitHub Desktop.
#!/bin/sh
# original src: https://unix.stackexchange.com/a/2146/17806
# usage: authkeys-report <authorized_keys-file>
set -ue
tmp="$(mktemp -t fingerprint-authkeys.XXXXXXXX)"
trap 'rm -f "$tmp"' 0
while read opts key; do
case "$opts" in
[0-9]*|ssh-dss|ssh-rsa|ssh-ed25519)
# not options, first "word" is part of key
key="$opts $key"
;;
esac
echo "$key" >$tmp
set -- $(ssh-keygen -lf "$tmp")
bits="$1" fingerprint="$2"
set -- $key # Note: will mangle whitespace in the comment
case "$1" in
[0-9]*) # SSH v1 key
type=rsa1
shift 3
;;
ssh-rsa|ssh-dss|ssh-ed25519) # SSH v2 key
type="$1"
shift 2
;;
*)
type=unknown
set --
;;
esac
printf '%-14s %-9s %s %s\n' "$type" "$bits" "$fingerprint" "$*"
done <$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment