How to fix "Remote Host Identification has Changed" error

Summary

You may encounter a scary-looking warning from time to time if you use SSH to log into other systems. The warning itself is real: you should double-check to make sure that you're not connecting to an imposter/man-in-the-middle server. However, oftentimes within FAU, we'll upgrade computers, etc, causing the key for the computer to change, thus giving remote users the error. This article explains the steps to remove the warning for the known-"good" computer and establish a remote connection again

Body

You may encounter a scary-looking warning from time to time if you use SSH to log into other systems. The warning itself is real: you should double-check to make sure that you're not connecting to an imposter/man-in-the-middle server. However, oftentimes within FAU, we'll upgrade computers, etc, causing the key for the computer to change, thus giving remote users the error. This article explains the steps to remove the warning for the known-"good" computer and establish a remote connection again.

Remote Host ID Changed?

You may encounter this error when trying to SSH into certain machines on the FAU network, especially if teams have been upgrading machines but keeping the same hostname, Resulting in changing the key associated with that host. The error looks something like this:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is SHA256:OKTA0P406BI9Nwqvd1vUTTUtk5rawo9BFVNUC8HOdX4
Please contact your system administrator.
Add correct host key in /home/yourusername/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/yourusername/.ssh/known_hosts:4
RSA host key for 192.168.123.234 has changed and you have requested strict checking.
Host key verification failed.
  

Most likely, you are not a victim to a man-in-the-middle attack. However, if you encounter this error when connecting to a machine that you know and trust, and has not been upgraded by Physics IT, then you should proceed with caution and/or contact us for help.


To fix the error you need to remove the stored key on your computer for the computer you're trying to connect to. Here are two ways to do this:

Method A: Use ssh-keygen -R

  • Run the following command (but replace 192.168.123.234 with the IP address or hostname (example.bast.hpc.fau.edu) of the machine you're trying to connect to.):
    ssh-keygen -R "131.91.163.15"

Method B: Manually edit your known_hosts file

  • You can use a text editor to remove the offending line in your ~/.ssh/known_hosts file. Look for the line in the error that says "Offending RSA key in /Users/yourUsername/.ssh/known_hosts:4". In this example, it's line 12 (note the ":12" at the end). So, open your known hosts file and delete line 12 and save.
  • You can do this using vim by running the following command from a terminal and then pressing the given keyboard shortcuts:
    1. vim ~/.ssh/known_hosts +12 (the "+12" at the end of the command tells vim to open the file and go to line 12)
    2. dd (Pressing lowercase d twice deletes the current line)
    3. ZZ (Pressing uppercase Z twice saves and quits vim)

After applying the fix, next time you try to SSH into that computer, you'll have to answer "yes" to confirm the connection. After that, it will be saved in known_hosts with the new key and you're good to go.

The only tricky thing might be if you're doing multiple-hop SSH tunneling w/ SSH pub key auth, you'll have to manually connect once just so you can answer "yes". This can cause issues if your tunneling/connection is part of a script that isn't expecting to have to answer "yes." So if you have a script that automatically SSHs through a Bastian tunnel to another Research Computing machine and performs some action on that remote machine, you'll probably want to go step by step and make sure the connection works at each step without asking for "yes or no". You'll only need to do that once.

If you have any questions, contact the Office of Information Technology Research Computing Team.

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @    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 a host key has just been changed.
    The fingerprint for the RSA key sent by the remote host is
    01:12:23:ab:bc:1a:1b:4c:5d:6e:7f:81:82:83:84:85.
    Please contact your system administrator.
    Add correct host key in /Users/yourUsername/.ssh/known_hosts to get rid of this message.
    Offending RSA key in /Users/yourUsername/.ssh/known_hosts:12
    RSA host key for 192.168.123.234 has changed and you have requested strict checking.
    Host key verification failed.

 

Original source: https://ithelp.metro.ucdavis.edu/kb/how-fix-remote-host-identification-has-changed-error

Details

Details

Article ID: 144690
Created
Thu 3/2/23 4:15 PM
Modified
Thu 3/2/23 4:15 PM