ssh-clean-keys Simple lines of code to clean invalid hosts from your .known_hosts-file. ssh-clean-keys () { for host in $1 $(dig +short $1); do echo "Cleaning $host"; ssh-keygen -R $host 2>&1 | sed -e 's,^,I,g'; done }