Skip to content

Instantly share code, notes, and snippets.

@jaygooby

jaygooby/unknown-host Secret

Last active Feb 10, 2021
Embed
What would you like to do?
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment