I recently bought a Raspberry Pi (model 4B with 2GB of RAM memory) to play a bit with HomeBridge and to also expand my knowledge on (basic) scripting and Linux in general.
After re-installing the Raspbian image on my Raspberry Pi, I tried to remotely connect to the Pi with SSH again via Terminal on macOS. However I was then greeted with the following error message:
thomasvanhoutte@Thomas-MacBook-Pro ~ % ssh [email protected]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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:Yjpzsxo3jodfkjdid8dfd8jjN/aKuuEEBrZ1KINgBhOI0A.
Please contact your system administrator.
Add correct host key in /Users/thomasvanhoutte/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/thomasvanhoutte/.ssh/known_hosts:1
ECDSA host key for 192.168.0.123 has changed and you have requested strict checking.
Host key verification failed.
I had no clue what it meant, but in the end I found the solution. The key that was already attached to this host was renewed due to the new image I put on the Pi. The solution is to remove all the keys associated with the Raspberry Pi device first with the following command:
ssh-keygen -R 192.168.0.123
If you encounter the same issue, and want to use the above piece of code to try to resolve it, don’t forget to change the IP address that is correct for your case.
The manual says the following about the -R parameter:
-R hostname Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed hosts (see the -H option above).