Created
May 29, 2019 02:45
-
-
Save kevinkjt2000/f6de9eadaf11bad93b7d3ecfbabc4099 to your computer and use it in GitHub Desktop.
This file contains 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 | |
#find all of the hosts listed in ~/.ssh/config | |
#apparently finding all the hosts ip/dns values is not trivial | |
grep -oPz 'Host .*\n HostName .*' ~/.ssh/config | | |
sed -n 'N;s/Host \(.*\)\n HostName \(.*\)/\1\n\2/p' | | |
while read hosts && read hostname; do | |
echo "$hostname" | |
if [[ "$hostname" == "%h"* ]]; then | |
for host in $hosts; do | |
echo " ${hostname//'%h'/$host}" | |
done | |
else | |
echo " $hostname" | |
fi | | |
while read host; do | |
echo -n " " | |
ssh-keygen -lf <(ssh-keyscan $host 2>/dev/null | awk '{print $2 " " $3 " " $1}') | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment