DEV Community

Shintaro Kaneko
Shintaro Kaneko

Posted on

2 3

SSH: Remove identified keys by hostname

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! :)

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay