Skip to content

Instantly share code, notes, and snippets.

@nopdotcom
Last active July 6, 2017 15:38
Show Gist options
  • Save nopdotcom/05fd9c6bc10a62fc09d058909a87d418 to your computer and use it in GitHub Desktop.
Save nopdotcom/05fd9c6bc10a62fc09d058909a87d418 to your computer and use it in GitHub Desktop.
When I’m initializing routers, they generate a new SSH host key. I know the “remote” host identity has changed. This fragment gives you a command to clean up the old host key, while expressing your frustration.
# usage:
# $ ssh 192.168.1.1
# ssh: The host key has changed!!!1
# $ fuck you, ssh
# nop@192.168.1.1:~$
fuck () {
local lastcmd=$(history -p '!!:0')
if [ "$lastcmd" != "ssh" ]; then
echo "The last command doesn't look like ssh."
set +x
return;
fi;
source "$HOME/fuck-you.sh"
fuck_internal "$@"
}
rerun_command_line=$(history -p '!!')
rerun_command=$(history -p '!!:0')
rerun_tail=$(history -p '!!:1-$')
rerun=$(bash -c "$rerun_command_line" </dev/null 2>&1 |
perl -n -e '/^Offending \w* key.*in ([^:]+):([0-9]+)/ && print "$1 $2\n";')
nuke_file_line () {
if [ -z "$1" ]; then
echo "Was the previous line an ssh invocation? I don't see it."
fi;
sed -i~ "$2,$2d" "$1"
}
# Intentionally not quoted.
#nuke_file_line $rerun
fuck_internal () {
if [ "$1" != "you" ] && [ "$1" != "you," ] || [ "$2" != "ssh" ] ; then
echo "Usage: fuck you[,] ssh"
else
history_offset=$(history 1 | awk '{print $1}')
history -d "$history_offset"
nuke_file_line $rerun
bash -c "$rerun_command -o 'CheckHostIP=no' -o 'StrictHostKeyChecking=no' $rerun_tail"
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment