SSH: Remove identified keys by hostname

kaneshin profile image Shintaro Kaneko ・1 min read

Failed to connect to the host via ssh.

Have you ever seen such a error which is "Failed to connect to the host via ssh." on your terminal when connecting a host via ssh. It should be happened if known_hosts file is taken a wrong identified keys belonging to the host.

$ ssh foobar@foobar.com
Failed to connect to the host via ssh.

-R hostname

To clear the problem you may take away the identified keys with ssh-keygen command.

$ man ssh-keygen

-R hostname
        Removes all keys belonging to hostname from a known_hosts file.  This option is useful to
        delete hashed hosts (see the -H option above).

Use f option to specify a known_hosts files.

$ ssh-keygen -f ~/.ssh/known_hosts -R foobar.com
# No more
# rm -f ~/.ssh/known_hosts

That's it! :)


markdown guide