Wednesday, 20 May 2015

Command to delete a particular host from known_hosts

Occasionally (especially in the cloud world, where instances are cattle), the SSH fingerprint for a host changes. When this happens, you will see a warning.
If the warning is expected, the usual remedy is to delete the offending key from your "known_hosts" file (typically found under ~/.ssh/known_hosts). However, when you need to do this across a bunch of machines and you don't know what line number the host will be on, on each machine, the following command might be useful:

sed -i -e '/\[\]:2222/d' ~/.ssh/known_hosts

It deletes any line which matches the host "[]:2222" in the default "known_hosts" file.

No comments: