#!/bin/bash echo $1 ssh-keygen -R $1 IP=$(getent hosts $1 |awk '{print $1}') ssh-keygen -R $IP # Remove the "-H" option in the two following lines if you want the hostnames # in known_hosts to be human readable (not hashed). ssh-keyscan -H $1 >>~/.ssh/known_hosts 2>/dev/null ssh-keyscan -H $IP >>~/.ssh/known_hosts 2>/dev/null