How to fix the "host key verification failed git" error?

Tim Mouskhelichvili
Tim Mouskhelichvili
• 2 minutes to read

When cloning (or doing other operations) through a remote server (for example, Github, Bitbucket, or Gitlab), a developer can get the "host key verification failed git" error. But what is this error, and how do you fix it?

The "host key verification failed git" error happens when a remote server's host key does not match the locally stored key.

This article explains this error and proposes a solution for fixing it.

Let's get to it 😎.

host key verification failed git

Why does this error happen?

The "host key verification failed git" error happens when a remote server's host key doesn't match the key stored inside your known hosts.

But what is this remote server's host key?

A remote server's host key verifies the remote server's identity and prevents man-in-the-middle attacks.

When you connect to a remote server for the first time (using SSH), its host key is stored inside a file called known_hosts inside the .ssh folder.

Each time you connect to the remote server, the key is verified.

If a remote server's host key changes (for example, if the server's IP changes), you will get an error.

How to fix this error?

To fix the "host key verification failed git" error you need to remove the incorrect key from your known_hosts and replace it with a valid one.

Here are the steps you need to follow:

1. Remove the old host key by running this command:

bashssh-keygen -R <hostname>

P.S. Replace <hostname> with a hostname (for example, github.com) or a remote server's IP address.

2. Add the new host key to your known host's list using this command:

bashssh-keyscan -t rsa <hostname> >> ~/.ssh/known_hosts

Alternatively, you can let SSH do it for you next time you connect using git push, git fetch, or via SSH.

You will get a warning message like so when trying to connect:

bashThe authenticity of host '<hostname> (<IP address>)' can't be established.
RSA key fingerprint is <fingerprint>.
Are you sure you want to continue connecting (yes/no)?

Type yes, and you are good to go!

Final thoughts

As you can see, fixing the "host key verification failed git" error is easy.

Although annoying, this security feature protects our data and information.

Let's be grateful that this feature exists!

host key verification failed git

Here are some other Git tutorials for you to enjoy:

Comments (0)
Reply to: