quickly delete a changed host

This warning will appear whenever a system has been reimaged, or ip has changed and you've previously connected to this device. To get around this warning simply run the sed command...


sed -i 12345d .ssh/known_hosts

where 12345 is the line number to be deleted

e.g.

In this instance, the bad host is saved at line 12 in .ssh/known_hosts

We can delete this line using a single sed statement


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
22:c6:35:c9:31:57:17:23:ad:a9:72:78:8e:af:c5:c5.
Please contact your system administrator.
Add correct host key in /home/sveraschockner/.ssh/known_hosts to get rid of this message.
Offending key in /home/sveraschockner/.ssh/known_hosts:12
RSA host key for 192.168.12.31 has changed and you have requested strict checking.
Host key verification failed.
luser@hostname:~$ sed -i 12d .ssh/known_hosts

I've written a little bash script that does this for me... yay.


#!/bin/bash
sed -i $1d ~/.ssh/known_hosts

usage

delhost 12