Add ssh_fingerprint (and ssh_fp alias)

Also update README.md
This commit is contained in:
Pandu POLUAN 2025-02-28 11:30:03 +07:00
commit 5e966203ae
2 changed files with 39 additions and 0 deletions

View file

@ -51,3 +51,35 @@ function ssh_unload_key {
ssh-add -d "$keyfile"
fi
}
############################################################
# Calculate SSH key fingerprint
function ssh_fingerprint {
local fptype
local quiet
local ansi
zmodload zsh/zutil
zparseopts -D -- md5=fptype q=quiet n=ansi
fptype="${fptype[*]}"
if [[ -z $fptype ]]; then
fptype="sha256"
else
fptype="${fptype:1}"
fi
if [[ -z ${ansi[*]} ]]; then
ansi=("\e[1;30m" "\e[0m")
else
ansi=("" "")
fi
local keyfiles=( "$@" )
if [[ ${#keyfiles[@]} == 0 ]]; then keyfiles=( "$HOME/.ssh/authorized_keys" ); fi
local f
for f in "${keyfiles[@]}"; do
if [[ $quiet != "-q" ]]; then printf "${ansi[1]}$f:${ansi[2]}\n"; fi
ssh-keygen -l -E "$fptype" -f "$f"
done
}
alias ssh_fp='ssh_fingerprint'