Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What the Warning Protects Against

Every SSH server has a host key. On your first connection ssh stores it in ~/.ssh/known_hosts on your computer. On every later connection it compares. If someone placed a machine between you and the server to read your session, that machine could not present the original key, and the comparison would fail. That is why ssh prints a large warning that the remote host identification has changed and stops with "Host key verification failed".

Take the warning seriously until you know why the key changed.

Common Legitimate Causes

  • The server was reinstalled: a fresh system creates new host keys.
  • The IP address was reused: a new server now has an address you connected to before.
  • The host keys were regenerated by an administrator.
  • Another machine answers on that address and port, for example after a change in port forwarding.

After a reinstall, the server has also lost your public key, so add it again with ssh-copy-id.

If none of these applies, do not connect, and find out what changed.

Step 1: Read the Warning

The message shows the fingerprint of the key the server now sends, its type (for example ED25519), and the file and line number of the stored entry that no longer matches. Note the fingerprint.

Step 2: Verify the New Fingerprint

Open the server console in your provider's control panel, which does not depend on SSH, and print the fingerprint of the same key type:

ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub

For an ECDSA or RSA key, use ssh_host_ecdsa_key.pub or ssh_host_rsa_key.pub. The SHA256: value must match the one in the warning exactly. If it does not, stop: something other than your server is answering.

Step 3: Remove the Old Entry

Only after the fingerprint matches, delete the stored key on your computer:

ssh-keygen -R your_server_ip

For a server on another port, the entry is stored with the port:

ssh-keygen -R "[your_server_ip]:2222"

If you also connect by host name, remove that entry too: ssh-keygen -R example.com. ssh-keygen keeps a copy of the original file as known_hosts.old and says so. It also works when the entries are hashed, as they are by default on Debian and Ubuntu.

Step 4: Connect Again

ssh user@your_server_ip

ssh treats the server as new and shows the fingerprint. Compare it with the one from the console once more, then type yes. The first-connection steps are in how to SSH into a server.

The Error Without a Warning

Scripts, cron jobs, and tools such as git, scp, or rsync can fail with "Host key verification failed" on a server they have never seen, because they cannot ask you to confirm. Connect once by hand from the same account, verify and accept the key, and the tool works afterward. For git hosts, see GitHub SSH key.

Do Not Turn the Check Off

You will find advice to set StrictHostKeyChecking no or to point UserKnownHostsFile at /dev/null. Both remove the protection completely: ssh would connect to any machine that claims the address. Remove the single outdated entry instead, as above.

Was this answer helpful?
Loading...