The Warning
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!This error means the server's host key doesn't match what's stored in your known_hosts file.
When This Is Expected
The key changes legitimately when:
- You rebuilt the server
- The server was reinstalled
- You're connecting to a different server at the same IP/hostname
- Cloud infrastructure was replaced
When This Is Suspicious
Be concerned if:
- You didn't change anything on the server
- Multiple people report this issue
- The server is production and shouldn't have changed
The Quick Fix
If you're sure the key changed legitimately, remove the old entry:
ssh-keygen -R server.example.com
# Or by IP
ssh-keygen -R 192.168.1.100Then reconnect. SSH will ask you to verify the new key:
ssh user@server.example.com
# Type "yes" to accept the new keyThe Safer Approach
If you're not sure, verify the new key with the server administrator or check it from the server console:
# On the server
ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub
# Or
cat /etc/ssh/ssh_host_ed25519_key.pubCompare this fingerprint with what SSH shows when you reconnect.
Edit known_hosts Manually
To remove a specific line from ~/.ssh/known_hosts:
```bash # Find the line number grep -n "server.example.com" ~/.ssh/known_hosts # Output: 42 server.example.com ssh-ed25519 AAAA...
# Delete line 42 sed -i '42d' ~/.ssh/known_hosts ```
Preventing Future Issues
For cloud servers that might be rebuilt, consider:
- 1.Using host aliases - Add to
~/.ssh/config:
Host myserver
HostName 192.168.1.100
User admin
UserKnownKnownHostsFile ~/.ssh/known_hosts_myservers- 1.Disabling strict checking (less secure, use only for throwaway servers):
Host temp-server
StrictHostKeyChecking no
UserKnownHostsFile /dev/null- 1.Persisting host keys - If you control the server, back up
/etc/ssh/ssh_host_*and restore after rebuild.