Remove host from SSH KnownHosts file without seeing the hostname

This post is mostly a bookmark for myself. I’ve been using search engines way too often to find this command..
The command to remove a host from a knownhosts file without seeing the actual hostname in the knownhosts file is the following:
[code]ssh-keygen -R HOSTNAME[/code]

As shown in this example:
joris@beanie ~
$ ssh myserverhost

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
02:d9:83:2a:bc:b1:ae:87:a0:9f:c5:d0:99:16:9d:cb.
Please contact your system administrator.
Add correct host key in /home/joris/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/joris/.ssh/known_hosts:102
RSA host key for myserverhost has changed and you have requested strict checking.
Host key verification failed.

joris@beanie ~
$ ssh-keygen.exe -R myserverhost

# Host myserverhost found: line 102 type RSA
/home/joris/.ssh/known_hosts updated.
Original contents retained as /home/joris/.ssh/known_hosts.old
joris@beanie ~
$ ssh myserverhost

The authenticity of host ‘myserverhost (10.8.14.198)’ can’t be established.
RSA key fingerprint is 02:d9:83:2a:bc:b1:ae:87:a0:9f:c5:d0:99:16:9d:cb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘myserverhost,10.8.14.198’ (RSA) to the list of known hosts.
Last login: Fri Mar 27 09:48:25 2015 from 10.8.14.75
[joris@myserverhost ~]$

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.