Skip to content

Instantly share code, notes, and snippets.

@djeikyb
Last active April 22, 2024 18:56
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 djeikyb/1ddfd9ea4d9005c526f4a2453ddabc1e to your computer and use it in GitHub Desktop.
Save djeikyb/1ddfd9ea4d9005c526f4a2453ddabc1e to your computer and use it in GitHub Desktop.

Get ssh thumbprint or ssh fingerprint of every entry in known_hosts as json:

ssh-keygen -l -f known_hosts  | awk '{ print "{" "\042host\042:\042" $3 "\042" ",\042thumbprint\042:\042" $2 "\042" ",\042alg\042:\042" $4 "\042" ",\042size\042:\042" $1 "\042" "}"}' | sort | jtbl

formatted:

ssh-keygen -l -f known_hosts \
    | awk '{ print "{" "\042host\042:\042" $3 "\042" ",\042thumbprint\042:\042" $2 "\042" ",\042alg\042:\042" $4 "\042" ",\042size\042:\042" $1 "\042" "}"}' \
    | sort \
    | jtbl

Awk needs octal escapes (hex is not portable) for quotes to avoid clashing with the shell. I chose double quotes 042 instead of single quotes 047

The host is first so the sort groups entries by host. The default order of known_hosts is newest entry at bottom.

jtbl is a nifty util to pretty-print the json as a table. Remove it to process the json lines with jq or any other json processor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment