# Remove the old entry ssh-keygen -R github.com # Re-add the updated key ssh-keyscan github.com >> ~/.ssh/known_hosts Use code with caution.
This resolves the "identity has changed" warning that causes go mod download to exit with an error. 3. Force SSH in Git Configuration go mod download host key verification failed
: In Docker or CI environments, the known_hosts file is often empty or missing, preventing the non-interactive Go command from confirming the host's identity. # Remove the old entry ssh-keygen -R github
: Go may be attempting to use SSH for a repository it previously accessed via HTTPS, or vice-versa, due to local gitconfig redirects like insteadOf . How to Fix the Error 1. Add the Host to known_hosts (Recommended) Force SSH in Git Configuration : In Docker
The error occurs when the Go toolchain attempts to download a private dependency via SSH, but the remote server’s identity cannot be verified against your local known_hosts file.
Go often defaults to HTTPS. If your private repository requires SSH keys for authentication, ensure your global Git config is set to rewrite HTTPS URLs to SSH:
This forces Go to use Git directly for those specific modules, respecting your SSH and known_hosts settings. 5. CI/CD Workaround (Lower Security)