Skip to content

Instantly share code, notes, and snippets.

@dreadwarrior
Created June 11, 2015 16:54
Show Gist options
  • Save dreadwarrior/ac982dddd023c5bd319b to your computer and use it in GitHub Desktop.
Save dreadwarrior/ac982dddd023c5bd319b to your computer and use it in GitHub Desktop.
ssh-keyscan.sh
echo "Probing SSH Servers for updating known_hosts file..."
SERVER_LIST=(server1.example.org server2.example.org)
for h in ${SERVER_LIST[*]}; do
ip=$(dig +short $h)
echo "Update known_hosts for ${h} with IP ${ip}"
ssh-keygen -R $h -f /home/vagrant/.ssh/known_hosts
ssh-keygen -R $ip -f /home/vagrant/.ssh/known_hosts
ssh-keyscan -H $ip >> /home/vagrant/.ssh/known_hosts
ssh-keyscan -H $h >> /home/vagrant/.ssh/known_hosts
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment