Skip to content

Instantly share code, notes, and snippets.

@mindware
Created March 7, 2015 07:43
Show Gist options
  • Save mindware/260c38312b931739191b to your computer and use it in GitHub Desktop.
Save mindware/260c38312b931739191b to your computer and use it in GitHub Desktop.
Bash script to clear old SSH hosts from known_hosts and rescan them
# say you save this as clear.sh
# chmod +x clear.sh
# usage: ./clear.sh <host1> <host2> <host..n>
for var in "$@"
do
echo "Clearing $var from host file."
ssh-keygen -f "$HOME/.ssh/known_hosts" -R $var
echo "Key scanning $var"
ssh-keyscan $var >> ~/.ssh/known_hosts
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment