0

I was normally working with the SSH on my server, then disconnected to re-connect using a different keypair, but received this 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 a host key has just been changed. The fingerprint for the ECDSA key sent by the remote host is SHA256:****. Please contact your system administrator. Add correct host key in /home//.ssh/known_hosts to get rid of this message. Offending ECDSA key in /home//.ssh/known_hosts:4 remove with: ssh-keygen -f "/home//.ssh/known_hosts" -R ec2-.us-east-2.compute.amazonaws.com ECDSA host key for ec2-**.us-east-2.compute.amazonaws.com has changed and you have requested strict checking. Host key verification failed.

I insisted and didn't work. Deleted the known host and didn't work.

Now the old keypair doesnt work either if i try to connect to ubuntu@ec2-**.us-east-2.compute.amazonaws.com. The new error is

Permission denied (publickey).

The only way to connect is directly using the public IP. I tried flushing the DNS cache and nothing. What could've happened?

3
  • Similar questions at stackexchange.com/…, possibly some of them might address the question of why an Amazon host's identification might have changed
    – mwfearnley
    Apr 4, 2018 at 11:21
  • I tried deleting all known_hosts and it didn't work. It says "Permission denied (publickey)".
    – Motheus
    Apr 4, 2018 at 16:29
  • The only way is connecting to the public IP. Get access denied every time when using the amazon domain.
    – Motheus
    Apr 4, 2018 at 16:47

2 Answers 2

1

You have a cached host key for that hostname in your ~/.ssh/known_hosts file. Did you previously connect to a host with this same name, but then replace the instance?

Either remove your ~/.ssh/known_hosts file entirely, or remove the entry for the hostname from the file in an editor.

3
  • I tried this: "Deleted the known host and didn't work. ". The error after the first one is "Permission denied (publickey)."
    – Motheus
    Apr 4, 2018 at 16:28
  • The only way is connecting to the public IP. Get access denied every time when using the amazon domain.
    – Motheus
    Apr 4, 2018 at 16:47
  • 1
    Are you connecting to the correct hostname? If the public IP has changed, the DNS will also change. Apr 5, 2018 at 7:45
1

Use this to remove the ssh keys belonging to a hostname or IP from your known hosts file.

ssh-keygen -R [hostname-or-IP]
2
  • You should always explain what a command does; I have done this for you this time, but you may wish to keep it in mind for future. Aug 5, 2021 at 17:21
  • @MichaelHampton thanks Michael
    – Ferose
    Aug 5, 2021 at 18:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .