Last active
September 24, 2015 01:54
-
-
Save tcotav/6914190dba79fad72bd6 to your computer and use it in GitHub Desktop.
Clean ssh known_hosts files for a specified user
This file contains hidden or 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 | |
| # ssh_key_clean.sh user site1 site2 site3 site4 | |
| user=$1 | |
| hostlist=`echo "${@:2}"` | |
| for hhost in $hostlist; do | |
| ip=$(dig +short $hhost) | |
| if [ -z "$ip" ];then | |
| echo "ERROR: couldn't get ip for host $hhost" | |
| exit 2 | |
| fi | |
| sudo -H -u $user bash -c "ssh-keygen -R $hhost" | |
| sudo -H -u $user bash -c " ssh-keygen -R $ip" | |
| sudo -H -u $user bash -c "ssh-keyscan -H $ip >> ~/.ssh/known_hosts" | |
| sudo -H -u $user bash -c "ssh-keyscan -H $hhost >> ~/.ssh/known_hosts" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment