Skip to content

Instantly share code, notes, and snippets.

@xofer
Last active August 29, 2015 14:13
Show Gist options
  • Save xofer/1eada9351e1691cd1405 to your computer and use it in GitHub Desktop.
Save xofer/1eada9351e1691cd1405 to your computer and use it in GitHub Desktop.
bash function to update host keys
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