Overview
This post will show you how to get rid of the warnings that appear while using SSH to connect to your domain/web server. The ‘host keys not matching’ notice is the subject of this guide:
You are exposed to a man-in-the-middle attack if you remove known host entries as described here.
The error message
When using SSH to access your domain or web server, the following warning usually signifies that the host key does not match the key in your known hosts file.
IT’S POSSIBLE THAT SOMETHING AWFUL IS GOING ON!
Right now, someone could be listening in on you (man-in-the-middle attack)!
It’s also conceivable that the RSA host key was just updated.
FOR SECURITY REASONS, THE FINGERPRINT FOR THE RSA KEY SENT BY THE REMOTE HOST HAS BEEN REMOVED.
If you have any questions, please contact your system administrator.
To get rid of this message, add the right host key to /home/username/.ssh/known hosts.
/home/username/.ssh/known hosts:10278 contains the offending key.
To prevent man-in-the-middle attacks, password authentication is deactivated.
To prevent man-in-the-middle attacks, keyboard-interactive authentication is disabled.
– This is usually not a cause for concern and can be fixed in a variety of ways.
Resolving the warning message
There are three ways to fix this problem. Please keep in mind that the remedy for this needs to be done on the client side, so if you’re having trouble connecting from home or work, you’ll need to upgrade that computer.
Method One — Generate a new host key (MAC or Linux)
If you’ve previously connected to a host, the old host key is saved in the /user/.ssh/known hosts file on your machine. You must now delete the old key from your PC if the key has been changed on the server.
In your shell, type the following command.
HOSTNAME should be replaced with the name of the host you’re connected to, such as example.com.
[local]
ssh-keygen -R HOSTNAME $ ssh-keygen -R HOSTNAME
The -R option deletes the old key associated with a particular hostname.
https://linux.die.net/man/1/ssh-keygen
You can now store a fresh key by connecting via SSH.
Method Two — Deleting your known_hosts file
Do not delete the known hosts file if you log in to other servers; otherwise, you will have no means of knowing whether your SSH keys have changed.
If you have multiple hosts that need to be changed, delete your whole known hosts file (on your local computer). It certifies the new key on the first log in.
The known hosts file is found in the.ssh/known hosts directory on a Mac or Linux workstation. To delete the known host file, simply type the following command in a terminal:
[local]
rm.ssh/known hosts rm.ssh/known hosts rm.ssh/
To remove the known hosts on a Windows machine using PuTTY, you must go into the registry:
Do a search for’regedit.exe’ and open it.
HKEY CURRENT USERSoftwareSimonTathamPuTTYSshHostKeys is the location to look for.
Delete all of the keys in there, or only the host key.
Method Three — Edit the known_hosts file
Edit the file known hosts. Open the file /home/username/.ssh/known hosts in your favourite text editor, and then delete the problematic line. Make sure you use your Shell user’s username.
This approach is similar to method two, except that instead of deleting the entire known hosts file, you only delete the single host line.
The line number is listed in the warning message, and it may be located after the file name in the error. The line number in the preceding error message is 10,278. If you’re using the “vim” editor on a Mac or Linux machine, you may simply type the following command to jump to that line:
$ vim +10278 [local]
The editor jumps right to that line. To save, press the ‘d’ key twice to remove that line, and then type the following:
[local]
😡 $
For further information on how to use vim, see the following article.
Using SSH to create and edit a file
Navigate to the Registry folder on a Windows machine using PuTTY, as explained in method two above. A list of hostnames appears in that directory. Select ‘Delete’ from the context menu after right-clicking on the one you want to get rid of.