This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# https://jay.gooby.org/2021/02/10/unknown-host | |
# | |
# 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