Skip to content

Instantly share code, notes, and snippets.

@craSH
Created May 16, 2015 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save craSH/b3d27b811e8ff2c203b0 to your computer and use it in GitHub Desktop.
Save craSH/b3d27b811e8ff2c203b0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function ssh-keygen-remove-all() {
if [ -n $1 ]; then
ssh-keygen -R "$1" >/dev/null 2>&1 && \
echo "Removed complete hostname: $1"
simple_host=$(echo $1 | cut -d '.' -f1)
if [ -n "$simple_host" ]; then
ssh-keygen -R "$simple_host" >/dev/null 2>&1 && \
echo "Removed short hostname: $simple_host"
fi
host_ip=$(dig +short "$1")
if [ -n "$host_ip" ]; then
for ip in "$host_ip"; do
ssh-keygen -R "$host_ip" >/dev/null 2>&1 && \
echo "Removed resolved hostname: $host_ip"
done
fi
fi
}
ssh-keygen-remove-all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment