diff --git a/bin/ssh-remove-known-host b/bin/ssh-remove-known-host new file mode 120000 index 0000000..3f8d2f5 --- /dev/null +++ b/bin/ssh-remove-known-host @@ -0,0 +1 @@ +../web/ssh-remove-known-host \ No newline at end of file diff --git a/web/ssh-remove-known-host b/web/ssh-remove-known-host new file mode 100755 index 0000000..723f7e4 --- /dev/null +++ b/web/ssh-remove-known-host @@ -0,0 +1,32 @@ +#!/bin/bash + +function helpexit() { + echo "Remove hosts from ~/.ssh/known_hosts" + echo "-f no questions." + exit +} + +for (( i=1; i<=$#; i++ )); do + [[ "${!i}" = "--help" ]] && helpexit + [[ "${!i}" = "-h" ]] && helpexit + [[ "${!i}" = "-f" ]] && { FORCE=1; continue; } + HOST="${!i}" +done +[[ -z "$HOST" ]] && helpexit + +HOST=$( ssh -G "$HOST" | awk '/^hostname / { print $2 }' ) +IP=$( getent hosts "$HOST" | awk '{ print $1 }' ) + +[[ "$FORCE" -ne 1 ]] && { + echo "Sure to remove $HOST (IP: $IP) from known_hosts? [y/N]" + read resp +} || { + resp=y +} + +[[ "$resp" = "y" ]] && { + set -x + ssh-keygen -R "$HOST" + ssh-keygen -R "$IP" +} +