Last active
April 6, 2022 02:49
-
-
Save dwlf/fbf6a8dc496750307a4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -n "$TRACE" ]]; then | |
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' | |
set -o xtrace | |
fi | |
set -o errexit | |
set -o pipefail | |
# Return ssh fingerprint in the form "he:xh:ex:he:xh:..." | |
# OpenSSH_6.8 changes the -l flag output. | |
function sshGetMD5Fingerprint() { | |
local sshPubKeyPath=$1 | |
local s | |
s=$(ssh-keygen -E md5 -l -f "$sshPubKeyPath" 2> /dev/null) | |
if [[ $? -eq 0 ]]; then | |
echo "$s" | awk '{print $2}' | tr -d '\n' | cut -d: -f2-; | |
else | |
# OpenSSH version < 6.8 | |
ssh-keygen -l -f "$sshPubKeyPath" | awk '{print $2}' | tr -d '\n'; | |
fi | |
} | |
# ---- mainline | |
echo $(sshGetMD5Fingerprint ".ssh/id_rsa.pub") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment