SOHO : Small Office Home Office
Freeware - Opensource software tips, tricks, tweaks & fixes for managing, securing, improving the performance of SOHO Desktop, Laptop, Networks

Wednesday, July 3, 2013

Remove offending RSA key in ~/.ssh/known_hosts file with one line command

When you ssh to a server where the host key (RSA) has changed then you will get an error message as shown in the image:

The error in the above example :
Offending RSA key in /home/username/.ssh/known_hosts:8

Looking in to the error message, we can find the offending RSA key and its position in the known_hosts file. In the above example image the offending key is at  line 8. (marked with red line). This can be fixed by deleting the offending key so that ssh lets you to connect after accepting the new key. This offending RSA key from the known_hosts file can be removed using `sed` with the following parameters:

$ sed -i '8d' ~/.ssh/known_hosts

The parameters
-i   :  For inplace editing
8d : Offending RSA key at line no 8
~/.ssh/known_hosts : path to and file known_hosts.

No comments:

Post a Comment