Skip to content

Instantly share code, notes, and snippets.

@Ozymandias42
Created November 29, 2024 20:43
Show Gist options
  • Save Ozymandias42/a64b20e922401a4e6d29e5846202a9d7 to your computer and use it in GitHub Desktop.
Save Ozymandias42/a64b20e922401a4e6d29e5846202a9d7 to your computer and use it in GitHub Desktop.
Bash wrapper using `column` for nicely formatted listing of SSH keys
#!/usr/bin/env bash
#Wrapper around ssh-add -l
#to show available Keys in properly formatted way
#and to optionally output as json
#Function getKeys() to get Keys in -l format with SHA256 sums or as key signature with -L
#Call by getKeys -keySigFormat[sha256|key]
function getKeys() {
[[ $keySigFormat == "sha256" ]] && ssh-add -l
[[ $keySigFormat == "key" ]] && ssh-add -L
}
function genOutput() {
case $keySigFormat in
"sha256") getKeys $keySigFormat | column -t -O 3,2,4,1 -N"Key-Length","SHA256Sum","File","Key-Type" $jsonFlag ;;
"key") getKeys $keySigFormat | column -t -O 3,1,2 -E2 -T2 -N"Key-Type","Key","File" $jsonFlag ;;
esac
}
function help(){
cat <<EOF
-h|-?|--help Get this help
--keysig [sha256|key] Chose format to show Keysignature in.
SHA256 or actual key. Defaults to SHA256
--json Output as JSON
EOF
}
keySigFormat="sha256"
jsonFlag=""
while test $# != 0; do
case $1 in
-h|-?|--help) help ; exit ;;
--keysig) keySigFormat=$2 ;;
--json) jsonFlag=-J ;;
esac
shift
done
genOutput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment