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

Use this command to remove entries from known_hosts:

ssh-keygen -R hostname

Yes, you can remove just one key. Just open it in an editor and delete the offending line. The number after the colon in the error message is the line number, so that's the line to delete -- line 1 in your example..


I have only recently started using host key's, but when I have messed with them it is generally one key per line so backup the file and remove them one at a time until you find the right one. Then add the others back. Bit of a long way to do it, but should work.

Also based on that error, and with no idea what so ever, it could be the first host key in the file that is the problem so open up the file with vim

vim ~/.ssh/known_hosts

and hit

dd

then save it.

Tags:

Ssh