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_hostto 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 ofssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pubon the server with the fingerprint your client might have previously stored (though you’d need to know what it was).
- On the client machine, run
-
Fix:
- On the client machine, remove the old, known host entry. The offending line is usually stored in
~/.ssh/known_hosts. Thessh-keygencommand can help remove it:
Replacessh-keygen -R remote_hostremote_hostwith 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.
- On the client machine, remove the old, known host entry. The offending line is usually stored in
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_hostwill 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 usingssh-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.
- Correct the client’s
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 -voutput 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.
- The
-
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_hoststo ensure the correct entry exists or remove any incorrect entries. You can also explicitly add the correct key usingssh-keyscan -H remote_host >> ~/.ssh/known_hostsafter verifying the key obtained byssh-keyscanis 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.
- Do NOT blindly remove the entry from
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
StrictHostKeyCheckingsetting than intended. A setting ofnowould suppress this warning entirely (which is bad for security), whileaskwould prompt you. The default isaskfor interactive sessions andyesfor non-interactive ones (like scripts). - Ensure the
UserKnownHostsFilein your~/.ssh/configor the system-wide/etc/ssh/ssh_configis pointing to the correct file. - On the server, check
/etc/ssh/sshd_configfor any unusual settings related to host key management.
- Check if your SSH client is configured to use a different
-
Fix:
- Correct
StrictHostKeyCheckingin~/.ssh/configtoaskoryesif it was inadvertently set tono. - Ensure
UserKnownHostsFilepoints 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.
- Correct
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.
- On the client:
-
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 ntpand thensudo systemctl enable ntp && sudo systemctl start ntp. - On CentOS/RHEL:
sudo yum install ntpand thensudo 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.