Ubuntu – Is it possible to remove a particular host key from SSH’s known_hosts file

ssh

Is it possible to remove a particular host key from SSH's known_hosts file?

I usually end up deleting the entire known_hosts file, which I have no problems with doing, but just out of curiosity, is it possible to remove just a single entry?

I opened the known_hosts file, but I am struggling to understand its contents.

Below is the message I faced, which led me to ask this question:

Add correct host key in /home/wissen16/.ssh/known_hosts to get rid of this message.
Offending key in /home/wissen16/.ssh/known_hosts:1
RSA host key for foo.com has changed and you have requested strict checking.
Host key verification failed.

Best Answer

Use this command to remove entries from known_hosts:

ssh-keygen -R hostname