It's not the first time that I am trying to ssh to my Raspberry Pi... I just removed the SD card and installed a new OS on it, enabled SSH, changed password, and connected it to Wi-Fi. I checked that it is connected and tried the hostname -I command to verify the IP address of my Raspberry Pi.

In the terminal of my Ubuntu installation, I tried to ssh to my Raspberry Pi - ssh [email protected]

And I got this error:

:~$ ssh [email protected]
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
Please contact your system administrator.
Add correct host key in /home/amina/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/amina/.ssh/known_hosts:7
  remove with:
  ssh-keygen -f "/home/amina/.ssh/known_hosts" -R ""
ECDSA host key for has changed and you have requested strict checking.
Host key verification failed.

My /home/amina/.ssh/known_hosts looks like:

cat /home/amina/.ssh/known_hosts
|1|/YaL+MeFfhwxhJ6tNw6N5aZH+9Y=|z8jsb+5wrjp8WlhT/YIQeIz4rwM= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
|1|27Ye2VAdFV0xpXqezJItT+MdE6g=|gWuaQ+AXzb+L5pXAiCrHcL7mOP0= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfj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DxyirGg4xWLMdy6ZlqchdC/m+tihnozx8700SJUypAmM=
|1|PJB8eX60NZoiUsKPR/3lOG6OIkc=|fDWSY6BHAXPoYKtl6Grt7zowUSY= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNhbkXF+WPzV0mF8ArmX6NLMerYJB2md/GdkYxdGULKoTOB/NT609J3cg8UXy5dp/e1OUsx30DxOuxYeK3vZ/9o=
|1|bOiopiRf/6i67YpOFb1dJHpYCmg=|W2gfZh+tPh44Abag6fEco7I2AM4= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMD3/sSZrM7nVqEAo7exASJNSOYGNwuibYoD7UVKM5P2niUsUxwg+6yiDnBCtes4V/GenVACkd4m8nUqz6ZcSCg=

I didn't know what I should edit, so I didn't do anything. Maybe I will make the situation worse. To ssh, I also used just two Raspberry Pi's.

I think that the three first lines are for one Raspberry Pi (the lines containesssh-rsa) and the other four lines are for the other Raspberry Pi since in the error they want me to edit line 7 /home/amina/.ssh/known_hosts:7. Also, the key that they gave me in the error does not fit any line (not the same number of characters). I didn't know exactly where to replace it.

I tried to reboot my Raspberry Pi and my laptop, but I got the same error.

I also removed the SD card and put it in my second Raspberry Pi and tried to ssh it and I got the same error... But when I put another SD card that contains another OS, I could ssh to my raspberry without any problem, and I put back the first SD card so I had this same error. So the problem probably comes from the OS in that SD card. How can I fix this?

  • 1
    The warning tell you what to do : remove with: ssh-keygen -f "/home/amina/.ssh/known_hosts" -R ""
    – Benoti
    Dec 31, 2020 at 9:56
  • so I just had to execute this command ssh-keygen -f "/home/amina/.ssh/known_hosts" -R "" I just thought that I had to edit the file, it didn't seem to me like a command at first but know when I saw the -f it is obvious that it's a command, I just get it now ! thank you !
    – mina
    Dec 31, 2020 at 10:16
  • 1
    If the address is known to be on your LAN then you shouldn't worry about MITM attacks. There's two options: 1. delete the known_hosts file. 2. disable known_hosts for LAN systerms unix.stackexchange.com/questions/225728/…
    – Dougie
    Jan 1, 2021 at 14:11

3 Answers 3


If you installed a new OS it has a new key.

Any existing connection history on your computer is meaningless. Delete it!

If you create a ~/.ssh/config you can disable StrictHostKeyChecking.
I use the following (on my iMac) to disable ONLY for my local network (for which it is unnecessary). You may get warnings, but get the option to connect.

Host 10.1.*.*
   StrictHostKeyChecking no
   UseKeychain yes
   BatchMode yes

You can edit .ssh/known_hosts, but it is often simplest to delete, it will be created when you establish a new connection.

  • Thank you, I just deleted it and it is working
    – mina
    Dec 31, 2020 at 10:19
  • ("an new OS""a new OS") Dec 31, 2020 at 21:08
  • Can you be more specific in your answer? Is it a file that should be deleted? If yes, which one and location in the file system. And/or some command to be issued? Dec 31, 2020 at 21:10
  • Other answers have a command example in them that someone can use/modify for their needs when they stumble across this answer. Jan 1, 2021 at 17:10

This is normal, if you have a new OS, you have a new fingerprint. Just do what it tells you:

ssh-keygen -f "/home/amina/.ssh/known_hosts" -R ""

After that you can connect again. The warning is to avoid MITM attacks since in that case the signature would be wrong. So never execute that command if you don't know why it changed!

  • I executed this command and it worked for me , thanks
    – mina
    Jan 4, 2021 at 8:21

If you know the IP address or DNS are correct, you can use:

$ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [email protected]

This can be added to your ssh config, however, not recommended, after confirm the connection is ok, use the 'ssh-keygen' command suggested by ssh.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.