Git error: "Host Key Verification Failed" when connecting to remote repository
You are connecting via the SSH protocol, as indicated by the ssh://
prefix on your clone URL. Using SSH, every host has a key. Clients remember the host key associated with a particular address and refuse to connect if a host key appears to change. This prevents man in the middle attacks.
The host key for domain.example
has changed. If this does not seem fishy to you, remove the old key from your local cache by editing ${HOME}/.ssh/known_hosts
to remove the line for domain.example
or letting an SSH utility do it for you with
ssh-keygen -R domain.example
From here, record the updated key either by doing it yourself with
ssh-keyscan -t rsa domain.example >> ~/.ssh/known_hosts
or, equivalently, let ssh
do it for you next time you connect with git fetch
, git pull
, or git push
(or even a plain ol’ ssh domain.example
) by answering yes when prompted
The authenticity of host 'domain.example (a.b.c.d)' can't be established. RSA key fingerprint is XX:XX:...:XX. Are you sure you want to continue connecting (yes/no)?
The reason for this prompt is domain.example
is no longer in your known_hosts
after deleting it and presumably not in the system’s /etc/ssh/ssh_known_hosts
, so ssh
has no way to know whether the host on the other end of the connection is really domain.example
. (If the wrong key is in /etc
, someone with administrative privileges will have to update the system-wide file.)
I strongly encourage you to consider having users authenticate with keys as well. That way, ssh-agent
can store key material for convenience (rather than everyone having to enter her password for each connection to the server), and passwords do not go over the network.
This is happening because github is not currently in your known hosts.
You should be prompted to add github to your known hosts. If this hasn't happened, you can run ssh -T [email protected]
to receive the prompt again.
As I answered previously in Cloning git repo causes error - Host key verification failed. fatal: The remote end hung up unexpectedly, add GitHub to the list of known hosts:
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
I had the similar issue, but, using SSH keys. From Tupy's answer, above, I figured out that the issue is with known_hosts file not being present or github.com not being present in the list of known hosts. Here are the steps I followed to resolve it -
mkdir -p ~/.ssh
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
ssh-keygen -t rsa -C "user.email"
- open the public key with this command
$ cat ~/.ssh/id_rsa.pub
and copy it. - Add the id_rsa.pub key to SSH keys list on your GitHub profile.