Quickly remove old ssh keys with sed
Our technicians stumbled across a great snippet about ssh keys:
http://www.watters.ws/view/article/181
If you work on a lot of servers and do a lot of reinstalls you will see the following error often.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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 a8:6a:60:5a:48:64:ac:90:33:b9:f2:7c:be:56:92:81. Please contact your system administrator. Add correct host key in /var/root/.ssh/known_hosts to get rid of this message. Offending key in /root/.ssh/known_hosts:9948 RSA host key for host.example.com has changed and you have requested strict checking. Host key verification failed.
To save some time you can quickly remove the old host key with a single sed command:
sed -i ‘9948d’ .ssh/known_hosts