Skip to content

Instantly share code, notes, and snippets.

@EHJ-52n
Last active September 24, 2020 11:27
Show Gist options
  • Save EHJ-52n/15778f3eaab87a4e9cc32f4c99299c5d to your computer and use it in GitHub Desktop.
Save EHJ-52n/15778f3eaab87a4e9cc32f4c99299c5d to your computer and use it in GitHub Desktop.
Script to generate a list of all ssh keys with all ciphers available. Source: https://superuser.com/a/1030779
#!/bin/bash
# Script print all key ids in md5 and sha256 that are available
# Execute the following to print the keys for your server:
# wget https://gist.github.com/EHJ-52n/15778f3eaab87a4e9cc32f4c99299c5d/raw/ -O ssh_server_keys.sh --quiet && chmod +x ssh_server_keys.sh && ./ssh_server_keys.sh && rm ssh_server_keys.sh
# standard sshd config path
SSHD_CONFIG=/etc/ssh/sshd_config
# helper functions
function tablize {
awk '{printf("| %-7s | %-7s | %-50s |\n", $1, $2, $3)}'
}
LINE="+---------+---------+----------------------------------------------------+"
# header
echo $LINE
echo "Cipher" "Algo" "Fingerprint" | tablize
echo $LINE
# fingerprints
for host_key in $(awk '/^#?HostKey/ {sub(/^#?HostKey\s+/,"");print $0".pub"};' $SSHD_CONFIG); do
cipher=$(echo $host_key | sed -r 's/^.*ssh_host_([^_]+)_key\.pub$/\1/'| tr '[a-z]' '[A-Z]')
if [[ -f "$host_key" ]]; then
sha256=$(awk '{print $2}' $host_key | base64 -d | sha256sum -b | awk '{print $1}' | xxd -r -p | base64)
echo $cipher SHA-256 $sha256 | tablize
echo $LINE
fi
done
echo "| State: $(date +%F\ %T) |"
echo "| https://gist.github.com/EHJ-52n/15778f3eaab87a4e9cc32f4c99299c5d/raw/ |"
echo "+------------------------------------------------------------------------+"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment