-
-
Save dale-c-anderson/eeeb7967141680ed4a4e243c70303010 to your computer and use it in GitHub Desktop.
Convert OpenSSH authorized_keys entries in to sha256 sums used in /var/log/auth.log
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 | |
set -eu -o pipefail | |
function main() { | |
AUTHORIZED_KEYS=${1:-~/.ssh/authorized_keys} | |
while read -r p; do | |
echo -e "\n$p ->" | |
echo "$p" | awk '{ print $2 }' | # Only the actual key data without prefix or comments | |
base64 -d | # decode as base64 | |
sha256sum | # SHA256 hash (returns hex) | |
awk '{ print $1 }' | # only the hex data | |
xxd -r -p | # hex to bytes | |
base64 # encode as base64 | |
done <<< "$(grep -v '^#' "$AUTHORIZED_KEYS")" | |
} | |
main "$@" | |
# thanks to https://serverfault.com/a/888300 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment