I find this error from time to time, so posting the solution here for easy finding:
This is what the error looks like after trying to run git pull
:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:uNi3ztkACsDhsr0u9e8aljQCVUdKZRDTBc3Cvj3tD2s.
Please contact your system administrator.
Add correct host key in /Users/myuser/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/myuser/.ssh/known_hosts:11Host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The solution is to run the following command:
ssh-keygen -R github.com
The ssh-keygen -R command is used to remove a host’s key from the user’s known hosts file.
When you connect to a remote host (like github.com) using SSH for the first time, its public key is stored in the known hosts file. This is done to ensure the authenticity of the host in subsequent connections. If the host key changes (for example, due to a server migration or a security update), you might encounter a warning or an error when connecting, as the stored key will not match the new key provided by the remote host.