Last active
August 29, 2015 14:13
-
-
Save xofer/1eada9351e1691cd1405 to your computer and use it in GitHub Desktop.
bash function to update host keys
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
hostkey () { | |
for HOST in "$@"; do | |
LIST=$HOST | |
PARTS=(${HOST//./ }) | |
if [[ ${#PARTS[*]} -gt 2 && "${PARTS[0]}" != "$HOST" ]]; then | |
LIST="$LIST ${PARTS[0]}" | |
fi | |
IP=$(dig +short $HOST) | |
if [ -n "$IP" ]; then | |
LIST="$LIST $IP" | |
fi | |
for ITEM in $LIST; do | |
echo "removing old key for <$ITEM>..." | |
ssh-keygen -f ~/.ssh/known_hosts -R $ITEM | |
echo "adding new key for <$ITEM>..." | |
ssh-keyscan $ITEM >> ~/.ssh/known_hosts | |
done | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment