Skip to content

Instantly share code, notes, and snippets.

@SharkyRawr
Created February 5, 2019 11:55
Show Gist options
  • Save SharkyRawr/d4842eba1c585299d219325ee58f445f to your computer and use it in GitHub Desktop.
Save SharkyRawr/d4842eba1c585299d219325ee58f445f to your computer and use it in GitHub Desktop.
Convert OpenSSH authorized_keys entries in to sha256 sums used in /var/log/auth.log
#! /bin/bash -ex
while read 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 < /root/.ssh/authorized_keys
# 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