How to fix "Host key verification failed"
Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with OpenSSH 9.6p1, client and server, November 29, 2026.
SSH refused to connect because it couldn’t confirm the server is the one it expects. There are two causes, and the line above the error tells you which:
No ED25519 host key is known for ... and you have requested strict checking, or no extra line at all: the server isn’t in yourknown_hostsfile, and SSH couldn’t ask you to accept it (a script, CI job orBatchMode).WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!: the server’s key is different from the one you saved. See our fix for a changed host key.
We reproduced both with OpenSSH 9.6 against a local server. With an empty known_hosts file and strict checking, SSH printed:
No ED25519 host key is known for [127.0.0.1]:2222 and you have requested strict checking.
Host key verification failed.
Run without a terminal to answer the prompt (input from /dev/null), it printed only Host key verification failed.
Fix: connect once in a terminal
If you’re at a keyboard, connect interactively. SSH shows the server’s fingerprint and asks Are you sure you want to continue connecting (yes/no/[fingerprint])?. Check the fingerprint against one you trust (the server’s admin, your cloud console or the service’s docs), then type yes. Later connections, including scripts and Git, pass the check.
To see a server’s fingerprint on the server itself:
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
In our test this matched what ssh-keyscan reported from the client: 256 SHA256:6HjC7noCf6BecUrYu4Ed1pnN94tB9JHf6unl+UVosXE.
Fix: scripts and CI pipelines
In GitLab CI, GitHub Actions or any script, add the server’s key to known_hosts before connecting. Get it with ssh-keyscan, check its fingerprint once, and store the line as a CI variable:
ssh-keyscan -p 22 -t ed25519 server.example.com # run once, check the output
mkdir -p ~/.ssh
echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts # in the CI job
Scanning inside every job trusts whatever answers at that moment, which defeats the check; scanning once and storing the result doesn’t. For services like GitHub, use the keys they publish in their SSH key fingerprints documentation.
If you’d rather let SSH add new hosts automatically, StrictHostKeyChecking accept-new does that and still refuses changed keys. In our test it printed Warning: Permanently added '[127.0.0.1]:2222' (ED25519) to the list of known hosts. and connected:
ssh -o StrictHostKeyChecking=accept-new user@server
Fix: Git says Host key verification failed
git clone git@github.com:... and git push use SSH underneath, so the same check applies. Connect once with ssh -T git@github.com, accept the key after comparing it with GitHub’s published fingerprint, then retry the Git command. If you then get Permission denied (publickey), the host check passed and the problem is your key: see Permission denied (publickey).
Confirm it worked
ssh-keygen -F server.example.com prints a line starting # Host server.example.com found, and the connection goes through. For how the known_hosts file works, including hashed entries and non-standard ports, see our known_hosts guide.
FAQ
Is it safe to set StrictHostKeyChecking no?
No. It accepts any key, including an attacker's, for every server. StrictHostKeyChecking accept-new is the safe middle ground: it adds hosts you've never seen and still refuses a key that changed.
Why does this happen in GitLab CI or GitHub Actions but not on my laptop?
The runner starts with an empty known_hosts file and can't answer a yes/no prompt. Add the server's key in the job before connecting, from a value you've checked, as shown on this page.
Why does git clone fail with this error?
Git uses SSH for git@ URLs, so the same check runs. Run ssh -T git@github.com (or your host) once in a terminal, compare the fingerprint with the host's published one and answer yes. After that, Git works.
