Git "Host key verification failed" in CI - Fix known_hosts
By Daniel Zoghalchali·Latchkey
SSH refused to connect because it cannot verify the remote host’s identity - the host key is not in known_hosts. On a fresh runner with no interactive prompt, SSH fails closed rather than asking you to trust the host.
git clone output
The authenticity of host 'github.com (140.82.x.x)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
Host key verification failed.
fatal: Could not read from remote repository.
01Symptom
What this error means
An SSH clone/fetch fails with Host key verification failed and fatal: Could not read from remote repository. It happens on clean runners that have never connected to the host before.
02Cause
Common causes
The host key is not in known_hosts
A fresh CI runner has an empty ~/.ssh/known_hosts. With no interactive TTY to accept the key, strict host-key checking aborts the connection.
StrictHostKeyChecking is on with no known host
SSH defaults to verifying the host. Without the key pre-seeded, verification fails by design - this is a safety feature, not a bug.
03Fix
How to fix it
Pre-seed the host key with ssh-keyscan
Add the verified host key to known_hosts before cloning. Pin it to the host you expect.
Pre-seed known_hosts with ssh-keyscan (and verify the fingerprint) in CI setup.
Bake the Git host’s key into the runner image where possible.
Avoid disabling StrictHostKeyChecking globally - it removes MITM protection.
Frequently asked questions
What causes Git "Host key verification failed" in CI?
There are 2 common causes: the host key is not in known_hosts and stricthostkeychecking is on with no known host. A fresh CI runner has an empty ~/.ssh/known_hosts.
How do I fix Git "Host key verification failed" in CI?
There are 2 fixes depending on which cause you have: pre-seed the host key with ssh-keyscan and let the checkout action manage ssh. Work through them in order, since the first is the most common.
What does Git "Host key verification failed" in CI actually mean?
An SSH clone/fetch fails with Host key verification failed and fatal: Could not read from remote repository.
How do I stop Git "Host key verification failed" in CI happening again?
Pre-seed known_hosts with ssh-keyscan (and verify the fingerprint) in CI setup. The prevention section lists 3 changes that keep it from recurring.
Latchkey managed runners at $0.0025/min at 2 vCPU, against $0.006 GitHub-hosted, and transient failures repaired on the runner.Start free →30-day trial · No credit card
Cookie Preferences
Choose which categories of cookies you want to allow. Essential cookies are always active as they are required for the site to function.
Essential
Required for the site to function.
Functional
Remembers your preferences like selected workspace and dashboard settings.
Analytics
Helps us understand how the site is used (Google Analytics).