“Git: Host Key Verification Failed” Error

Nearly every developer on the planet has heard or has ever used Git and other associated Git services such as hosting platforms with GitHub, GitLab, GoGs, etc.

When performing the Git operations such as cloning a repository, you might encounter the “Git: Host key verification failed” error message.

This can be inconvenient especially for new Git users as they do not know how to troubleshoot it. In this post, we will explore what this error means and how to fix it to allow you to perform your desired Git operations.

What Causes this Error?

The best way to find the root cause of an error is to understand what it means. In Git, the “host key verification failed” error means that the remote server’s host key does not match the one that is stored in your known hosts.

In SSH, the “known_hosts” is a text file that stores a list of host keys for all the remote servers that you previously connected to. Each line in the “known_hosts” file contains the hostname or IP address of the remote machine and the associated public key.

An example output is as follows: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMI63NHdHkXQKHZpUBbmI/3xGLhZFjnsV89q1q8la5yo ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIO+I3YnC3nA20lZ2g7cgACU/ YhY1yBC0aQrcgscghRww8n1NLwfSZI6SInkUJfNu6xRJRTTbj14h5RZDgxmPKg=

The remove server’s host key is used to uniquely identify and authenticate a remote server when establishing an SSH connection.

The operation verifying the key is carried out every single time you attempt to connect to the remote server.

As a result, if the host key of the remote server changes while you still have an outdated copy of the key, you will get this error.

Essentially, it means that the host key that you have on your local machine is different than the one on the remote machines. This can be as simple as a change of the IP address of the remote machine.

How to Fix It

To fix this error, all you need to do is remove the outdated copy of the host key and replace it with the new one.

To remove the old host key, run the following command:

$ ssh-keygen -R <hostname/IP>

Replace the hostname or IP address with the actual hostname or IP address of the remote server’s IP address.

Next, add a new host key to the “known_hosts” file using the following command:

$ ssh-keygen -t rsa <hostname/IP> >> ~/.ssh/known_hosts

This should add the new host key of the remote machine into your “known_hosts” file.

NOTE: However, the most recommended method is to login into the remote server and allow SSH to handle the process of adding the new host file into your machine.

For Git, you can do this by running “git push” or “git fetch” command.


In this post, we explored the cause of the “Git: Host key verification failed” error when performing the Git operations and how to resolve it.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list