From 3a1bb75771e0ee1aa4d3adb7bb64714fce8d3151 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Wed, 2 Aug 2017 12:16:02 +0300 Subject: [PATCH] ssh fingerprint remover --- bin/ssh-remove-known-host | 1 + web/ssh-remove-known-host | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 120000 bin/ssh-remove-known-host create mode 100755 web/ssh-remove-known-host 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" +} +