summaryrefslogtreecommitdiff
path: root/remove-known-host.sh
blob: 04ead3e5ce80b3f49d4197e61bf72a9b127fea97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

if [ -z "$1" ]; then
  echo "$0 <host>"
  exit 1
fi

short="$1"
ssh_host=$(ssh -G "$short" | grep "^hostname " | awk '{ print($2) }' )
ssh_port=$(ssh -G "$short" | grep "^port " | awk '{ print($2) }' )

cd "${BASH_SOURCE%/*}"
source common/utils.sh
ansible_variable__get host_name "$short" || exit 1
ansible_variable__get host_domain "$short" || exit 1


for name in "$short" "$ssh_host" "$ssh_host:$ssh_port" "[$ssh_host]:$ssh_port" "$host_name" "$host_name.$host_domain"; do
  ssh-keygen -f "$HOME/.ssh/known_hosts" -R "$name"
done

exit 0