# Git "Host key verification failed" in CI - Fix known_hosts

> Fix Git "Host key verification failed" in CI - the Git host is not in known_hosts, so SSH aborts before authenticating. Add the host key the right way.

Source: https://latchkey.dev/learn/git/git-host-key-verification-failed  
Updated: 2026-06-25

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.

## Diagnose it: depth, refs, or credentials?

```Terminal
git rev-parse --is-shallow-repository
git rev-parse --abbrev-ref HEAD    # prints HEAD when detached
git log --oneline -3
git remote -v
```

> `actions/checkout` fetches depth 1 on a detached HEAD. Anything diffing against a base, reading a branch name, or running `git describe` needs `fetch-depth: 0`.

## FAQ

### 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 runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
