Last active
July 20, 2019 19:52
-
-
Save Torstein-Eide/937e5e5ce25a99c6e4aab47722cd2602 to your computer and use it in GitHub Desktop.
kontroller-ssh-knownhost
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/sh | |
## source: https://serverfault.com/questions/29262/how-to-manage-my-ssh-known-hosts-file | |
list=`cat ~/.ssh/known_hosts | awk '{print $1}' |sed -e 's/,/ /g' | sort -u ` | |
listsorted=$(printf "%s\n" ${list[@]} | sort -u) | |
echo $listsorted | |
#listsorted="10.2.10.1" | |
echo > /tmp/sshstat.txt | |
for host in $listsorted ; | |
do | |
echo $host | |
ssh -oBatchMode=yes -oConnectTimeout=2 root@${host} "exit" >/tmp/sshstat.txt 2>&1 | |
ret=$? | |
if [ $ret -ne 0 ]; then | |
echo "Failed: $host" | |
echo sed -i.bak \"/$host/d\" "~/.ssh/known_hosts" | sh | |
else | |
grep "Offending RSA" /tmp/sshstat.txt | sed -e 's/:/ /g' | awk '{printf "sed -i.bak -e \"%dd\" %s \n", $6, "~/.ssh/known_hosts" }' | sh | |
fi | |
done | |
#echo $list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment