I updated a server cluster last night and was getting loads of
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
warnings. You get told about the offending line number:
Offending RSA key in ~/.ssh/known_hosts:531
And usually I’d just edit it and be done, but after doing it a couple of times I wrote unknown-host
#!/bin/bash
#
# Use this to remove the offending line from your
# ~/.ssh/known-hosts file when you know the host
# has actually changed and you get the
#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#
# Offending RSA key in ~/.ssh/known_hosts:531
#
# warning telling you what line needs removing.
#
# usage: unknown-host <line number>
#
# So calling:
#
# unknown-host 531
#
# will remove line 531 and then you can ssh again with the nag.
#
# jay@gooby.org
# @jaygooby
line=$1
# number detection via https://stackoverflow.com/a/3951175/391826
case $line in
''|*[!0-9]*) line="" ;;
esac
if [ -z "$line" ]; then
echo -e "Usage: $(basename $0) <line number>" >&2
exit 1
else
sed -i"" -e "${line}d" ~/.ssh/known_hosts
fi
so I wouldn’t have to do that again, in the great spirit of xkcd’s “Automation” webcomic
Top comments (0)