The “REMOTE HOST IDENTIFICATION HAS CHANGED” error appears during SSH connections when the server’s host key does not match the one previously stored in your ~/.ssh/known_hosts file. This mismatch can occur when connecting to a server on a non-default port (not port 22), especially if the server was reinstalled, its SSH keys were regenerated, or the port configuration changed. This error is a security feature designed to prevent man-in-the-middle attacks, but it can also result from legitimate server changes or port reassignments.
Update or Remove the Outdated Host Key Entry
known_hosts file, such as [hostname]:port. For example, if you connect to example.com on port 2222, the entry will appear as [example.com]:2222.~/.ssh/known_hosts file in a text editor. You can use nano, vim, or any editor of your choice.nano ~/.ssh/known_hosts
yes to proceed. This adds the new key to your known_hosts file.Join readers who trust AllThings.How
Add us as a preferred source on Google so our practical guides show up first next time you search.
Add to Google Preferences →Remove the Host Key Entry Using ssh-keygen
ssh-keygen -R command to remove the problematic host and port entry automatically. Replace hostname and port with the actual values:ssh-keygen -R [hostname]:port
This command searches your known_hosts file and deletes the entry for the specified host and port.
Clear All Known Hosts Entries (Use With Caution)
If you have many outdated entries or want to reset your trusted hosts list, you can clear the entire known_hosts file. This approach removes all host key records, requiring you to verify every SSH connection anew.
cp ~/.ssh/known_hosts ~/.ssh/known_hosts.bak
truncate -s 0 ~/.ssh/known_hosts
Or simply delete it:
rm ~/.ssh/known_hosts
Resolving the SSH “REMOTE HOST IDENTIFICATION HAS CHANGED” error for connections using a port specifier ensures secure and uninterrupted access to your servers. Always confirm new host keys to protect against unauthorized access, and maintain your known_hosts file for smooth SSH operations.






