I am trying to connect to a remote Git repository that resides on my web server and clone it to my machine.
I am using the following format for my command:
git clone ssh://username@domain.example/repository.git
This has worked fine for most of my team members. Usually after running this command Git will prompt for the user’s password, and then run the cloning. However, when running on one of my machines I get the following error:
Host key verification failed.
fatal: Could not read from remote
repository.
We are not using SSH keys to connect to this repository, so I’m not sure why Git is checking for one on this particular machine.
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.examplehas changed. If this does not seem fishy to you, remove the old key from your local cache by editing${HOME}/.ssh/known_hoststo remove the line fordomain.exampleor letting an SSH utility do it for you withFrom here, record the updated key either by doing it yourself with
or, equivalently, let
sshdo it for you next time you connect withgit fetch,git pull, orgit push(or even a plain ol’ssh domain.example) by answering yes when promptedThe reason for this prompt is
domain.exampleis no longer in yourknown_hostsafter deleting it and presumably not in the system’s/etc/ssh/ssh_known_hosts, sosshhas no way to know whether the host on the other end of the connection is reallydomain.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-agentcan 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.