When cloning through a remote server (for example, GitHub), you can get the host key verification failed git
error. This error had been occurred so many times in my coding practice, and even coworkers have faced it, so I decided to write a little blog post to share with you how to resolve it.
But what is this error, and how do you fix it?
Why Host Key Verification Failed
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. 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
1. Verify that the SSH keys have been set up correctly, so run this command below.
$ ssh-keygen
2. Next, enter the password and keep the default path ~/.ssh/id_rsa
.
3. Now, you have to add the public key (~/.ssh/id_rsa.pub
) to GitHub account.
4. Add the host key to your known host's list using this command:
$ ssh-keyscan -H rsa <hostname> >> ~/.ssh/known_hosts
Replace <hostname>
with a hostname (for example, github.com) or a remote server's IP address.
You will get a warning message like this:
The 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!
🔍. Similar posts
How to Fix Mutation Bugs in Your React Complex State Logic
10 Feb 2025
Everything You Need to Know About CSS Style Rules
09 Feb 2025
How to Use Form Controls and Data Binding Effectively in React Forms
08 Feb 2025