Host Identification Has Changed

Published

When trying to connect to a host after reinstalling its operating system, you may encounter the following message:

		
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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)! It is also possible that the RSA host key has just been changed. The fingerprint for the RSA key sent by the remote host is 4e:10:78:39:a6:cd:11:10:3a:cd:1b:a2:91:cd:e5:5c. Please contact your system administrator. Add correct host key in /home/user/.ssh/known_hosts to get rid of this message. Offending key in /home/user/.ssh/known_hosts:1 RSA host key for 203.0.113.12 has changed and you have requested strict checking. Host key verification failed.

This warning indicates that the host key stored in your known_hosts file does not match the key presented by the server. This could be due to legitimate changes such as security updates or OS reinstallation, but it may also indicate a potential security threat, such as a man-in-the-middle attack. In this attack, a cybercriminal intercepts data transmitted between two devices.

If the host key change is confirmed to be legitimate, you can use the solutions below to resolve the issue. Otherwise, there is a risk that data transmitted between the host and your client device may be intercepted.

Possible Solutions:

1. Removing Irrelevant Host Keys.

The safest and most precise method is to remove only the irrelevant host key from the list of known hosts on your client device. You can do this using a command in PowerShell or a Linux terminal:

		
ssh-keygen -R <host_IP_address> [:<host_port>]

where:

  • <host_IP_address> - The IP address or DNS name of the server whose data you want to remove from the known_hosts file, which contains information about known hosts.
  • [:<host_port>] - The network port the server uses for SSH connections, which needs to be removed from the known_hosts file. This is an optional parameter required if a non-standard TCP port was specified for connecting to the host.

For example:

		
ssh-keygen -R 203.0.113.12

This command will remove the existing host key for IP address 203.0.113.12 from the current user's known_hosts file.

You can also manually remove outdated host information from the known_hosts file by editing it in a text editor. To do this, find the line starting with the server's IP address that you are unable to connect to, delete it completely, and save the changes.

By default, the path to the known_hosts file is as follows:

  • Linux: /home/<username>/.SSH/known_hosts;
  • Windows: C:\Users\<username>\.SSH\known_hosts;
  • macOS: /Users/<username>/.SSH/known_hosts.

2. Deleting the known_hosts File.

If your device uses OpenSSH to access only one host, you can simply delete the known_hosts file, which contains information about hosts. If the known_hosts file is absent, OpenSSH will request a new key from the host on the next connection attempt, create a new known_hosts file, and record host information in it.

However, this method is not suitable for systems that use SSH to access multiple hosts. Deleting the known_hosts file will result in the loss of information about all hosts, which can lead to failures, especially in automated connections.

You can delete the known_hosts file for the current user as follows:

  • In Windows via PowerShell:
		
Remove-Item c:\Users\$env:UserName\.SSH\known_hosts
  • In a Linux and macOS terminal:
		
rm ~/.ssh/known_hosts


You can also manually delete the known_hosts file by finding it through a file manager. By default, the path to the known_hosts file is as follows:

  • Linux: /home/<username>/.SSH/known_hosts;
  • Windows: C:\Users\<username>\.SSH\known_hosts;
  • macOS: /Users/<username>/.SSH/known_hosts.