Skip to content

Instantly share code, notes, and snippets.

@grizmio
Last active August 9, 2017 17:47
Show Gist options
  • Save grizmio/597471ac23cd033aec610ab5a2eda1fe to your computer and use it in GitHub Desktop.
Save grizmio/597471ac23cd033aec610ab5a2eda1fe to your computer and use it in GitHub Desktop.
Easily remove a line from ~/.ssh/known_hosts on a MAC
http://blog.grizmio.cl/post/157828022813/easy-fast-bash-removeline
On a MAC sed needs -i '' on a Linux box it won´'t.
This is the most annoying message you could read in a ssh hurry:
baz:foo grizmio$ ssh root@192.168.1.2
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:+ZAA333A4Ar488888888AAAAAnzi08nv8NvAAAddAAAbbbAAAAA.
Please contact your system administrator.
Add correct host key in /home/grizmio/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/grizmio/.ssh/known_hosts:8
ECDSA host key for 192.168.1.2 has changed and you have requested strict checking.
Host key verification failed.
Add to ~/.bashrc file:
removesshline() {
sed -i '' "$1d" ~/.ssh/known_hosts
}
baz:foo grizmio$ . ~/.bashrc
baz:foo grizmio$ removesshline 8
baz:foo grizmio$ ssh root@192.168.1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment