The REMOTE HOST IDENTIFICATION HAS CHANGED warning means your SSH client thinks the server it’s connecting to is a different server than it connected to before, and it’s rightfully freaking out. This is a security feature designed to prevent man-in-the-middle attacks.

Here’s why your SSH client is showing this warning and how to fix it, ranked by likelihood:

1. The Server’s Host Key Actually Changed (Legitimate Change)

This is the most common and usually the most benign reason. The server administrator reinstalled the operating system, replaced the network interface card (which has a MAC address often tied to host key generation), or deliberately regenerated the server’s SSH host keys.

  • Diagnosis:

    • On the client machine, run ssh -v user@remote_host to see the full debug output. Look for lines like @@@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @@@ followed by the specific key that changed.
    • On the server machine, check the host key files. The primary ones are /etc/ssh/ssh_host_rsa_key.pub, /etc/ssh/ssh_host_ecdsa_key.pub, and /etc/ssh/ssh_host_ed25519_key.pub. If these files are new or their contents differ from what your client used to know, this is the cause. You can compare the output of ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub on the server with the fingerprint your client might have previously stored (though you’d need to know what it was).
  • Fix:

    • On the client machine, remove the old, known host entry. The offending line is usually stored in ~/.ssh/known_hosts. The ssh-keygen command can help remove it:
      ssh-keygen -R remote_host
      
      Replace remote_host with the actual hostname or IP address you’re connecting to. This command will prompt you to confirm removal.
    • This works because you’re telling your SSH client to forget the old, invalidated identity of the remote server, allowing it to establish trust with the new identity on the next connection.

2. You’re Connecting to a Different Server with the Same IP Address

This is rare but critical. A new server (or a reconfigured one) has been deployed using an IP address that your client previously associated with a different server. This could happen in dynamic environments or if IP addresses were reused without proper network cleanup.

  • Diagnosis:

    • This is harder to diagnose directly from the SSH client warning alone, as it just sees a changed key. The key is the same as a previous server, but the server itself is different.
    • To confirm, you need to investigate the network. Check your DHCP server logs, DNS records, or network configuration management tools to see which server should be at that IP address. Compare the MAC address of the network interface on the server responding to your SSH connection with the expected MAC address for that IP.
    • On the client, ssh -v user@remote_host will show the fingerprint of the new server. You’ll need to cross-reference this with known fingerprints of servers in your environment.
  • Fix:

    • Correct the client’s known_hosts: Similar to the first case, you’ll remove the old entry using ssh-keygen -R remote_host.
    • Investigate and correct the IP address assignment: The real fix is to ensure IP addresses are correctly assigned and not reused unexpectedly. This might involve updating DNS, reconfiguring DHCP, or fixing network infrastructure.
    • Removing the old entry on the client allows it to connect to the new server now at that IP, but it doesn’t fix the underlying network misconfiguration.

3. Man-in-the-Middle (MITM) Attack

This is the worst-case scenario. An attacker is intercepting your SSH connection, presenting a fake server identity to you, and then (often) connecting to the real server on your behalf. The warning is your client correctly identifying that the server’s identity doesn’t match what it expected.

  • Diagnosis:

    • The ssh -v output will show the warning. The key difference from a legitimate change is that you likely didn’t expect the host key to change, and there’s no obvious reason for it.
    • If possible, try connecting to the server from a different, trusted network or using a different client machine. If the warning disappears or shows a different key, it strongly suggests your original connection path is compromised.
    • Examine the network traffic between your client and the server if you have the tools (e.g., tcpdump, Wireshark) and expertise. Look for unusual connections or unexpected SSH server banners.
  • Fix:

    • Do NOT blindly remove the entry from known_hosts. If you suspect a MITM attack, blindly removing the entry allows the attacker to establish a new "trusted" connection.
    • Isolate the client machine: Disconnect it from the network.
    • Verify the server’s identity: Contact the server administrator through a separate, trusted channel (phone call, in-person, a different secure communication method) and ask them to confirm the server’s current host key fingerprint.
    • Once you have the correct fingerprint from a trusted source, you can manually edit ~/.ssh/known_hosts to ensure the correct entry exists or remove any incorrect entries. You can also explicitly add the correct key using ssh-keyscan -H remote_host >> ~/.ssh/known_hosts after verifying the key obtained by ssh-keyscan is the legitimate one.
    • The fix is to break the attacker’s connection and re-establish a secure, direct path to the legitimate server, ensuring you trust its identity.

4. SSH Client or Server Configuration Issues

Less common, but sometimes misconfigurations can lead to the client perceiving a change.

  • Diagnosis:

    • Check if your SSH client is configured to use a different StrictHostKeyChecking setting than intended. A setting of no would suppress this warning entirely (which is bad for security), while ask would prompt you. The default is ask for interactive sessions and yes for non-interactive ones (like scripts).
    • Ensure the UserKnownHostsFile in your ~/.ssh/config or the system-wide /etc/ssh/ssh_config is pointing to the correct file.
    • On the server, check /etc/ssh/sshd_config for any unusual settings related to host key management.
  • Fix:

    • Correct StrictHostKeyChecking in ~/.ssh/config to ask or yes if it was inadvertently set to no.
    • Ensure UserKnownHostsFile points to the expected location (usually ~/.ssh/known_hosts).
    • These fixes ensure your SSH client is behaving as expected regarding host key verification, rather than masking or misinterpreting the process.

5. Time Skew Between Client and Server

While not directly causing a host key change, significant time differences can sometimes interfere with cryptographic operations or logging that might indirectly lead to confusion or perceived issues. It’s a long shot for this specific error, but good practice for general SSH stability.

  • Diagnosis:

    • On the client: date
    • On the server: date
    • Compare the outputs. If they differ by more than a few minutes, it’s significant.
  • Fix:

    • Ensure Network Time Protocol (NTP) is configured and running on both the client and server.
    • On Debian/Ubuntu: sudo apt update && sudo apt install ntp and then sudo systemctl enable ntp && sudo systemctl start ntp.
    • On CentOS/RHEL: sudo yum install ntp and then sudo systemctl enable ntpd && sudo systemctl start ntpd.
    • Synchronizing clocks ensures that timestamps used in security protocols and logs are consistent, preventing potential issues that could manifest as unexpected behavior.

After resolving the REMOTE HOST IDENTIFICATION HAS CHANGED warning by correctly identifying the cause and updating your known_hosts file, the next error you’ll likely encounter if the underlying issue was a MITM attack is a persistent connection failure or continued suspicious behavior from the server.

Want structured learning?

Take the full Ssh course →