27

I'm trying to ssh into my UBUNTU through my PC with Cygwin on it. I can WINSCP without a hitch, however when I ssh through a command line it comes up with this error:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
5d:84:de:4e:a8:81:df:22:06:23:98:34:cd:26:f5:1a.
Please contact your system administrator.
Add correct host key in /home/Trevor/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/DIRECTORY
ECDSA host key for HOSTNAME has changed and you have requested strict checking.
Host key verification failed.

So I looked it up and it said that I needed to change my host key in my .ssh folder that's located in my home folder. Well, there wasn't one so I made one. Tried again and got the same error.

What to do?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1985351
  • 4,589
  • 6
  • 22
  • 25

9 Answers9

37

"Host key verification failed" means that the host key of the remote host was changed.

Ssh stores the host keys of the remote hosts in ~/.ssh/known_hosts. You can either edit that text file manually and remove the old key (you can see the line number in the error message), or use

ssh-keygen -R hostname
Kampai
  • 22,848
  • 21
  • 95
  • 95
Suhas.s
  • 471
  • 4
  • 5
12

try

 rm -f /home/user/.ssh/known_hosts

or deletes the offending key from the known_hosts

ssh-keygen -R hostname
Gabber
  • 7,169
  • 3
  • 32
  • 46
  • 1
    worked for me when used like this >>> rm -f /root/.ssh/known_hosts – buddhiv Aug 14 '18 at 09:56
  • removed the file and it's still not working. Is there another possible path? – Senju Jul 21 '19 at 17:47
  • 1
    @AmitDubey I solved it. There is one known_hosts file for ssh and there is one known_hosts file for sudo ssh, that's why :) ~/.ssh/known_hosts and /var/root/.ssh/known_hosts – Senju Jul 22 '19 at 10:16
3

This generally means that the host key of your remote host has been changed. It can be used to avoid the men in the middle attacks and to make your host secure. You can simply remove this using:

ssh-keygen -R hostname | ip address 

or

ssh-keygen -f "/root/.ssh/known_hosts" -R ip address
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Saboor
  • 352
  • 1
  • 10
2
  1. go to known_hosts vim ~/.ssh/known_hosts
  2. delete the hostname that is causing this issue HOSTNAME
Sbk3824
  • 1,229
  • 1
  • 14
  • 24
2

It mainly happens when your remote server keys changes and your system has the old key. So we need to clear the key of your remote server in the below file.

  1. ]#vi ~/.ssh/known_hosts
  2. Delete the host entry in the file that is causing the problem.like the below

1x.xx.xx.xx ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHvbhdjhyyeindHAyNTYAAABBBAMazUadnY2m81h0qVQyaKN3tiUSrIPw42rz7orVM9gusGpDDxtFbjMwxpjGOevVba1KNY5eI1yZx9U+uTz0Jpc=

3.save the file and retry with your login.

Manas
  • 71
  • 2
1

So looks like your ubuntu host key changed since you ssh to it from Cygwin last time.

The message already told you what to do,

cd /home/Trevor.ssh 
open know_hosts file and delete the old key of your ubunto box 
once the key is removed, ssh to your ubuntu box again
Ask and Learn
  • 8,661
  • 8
  • 37
  • 43
0

Tested in Mac and Ubuntu 16.04

ECDSA host key for HOSTNAME has changed and you have requested strict checking. Host key verification failed. means,

If you get this error message then the host you are trying to connect was connected before and possibly the EDSA key is now a mismatch. This typically happens when you are under the DHCP network and multiple devices are allocated with the same IP at different instances of time. As a result the there is a key mis-match i.e. the EDSA key is catched into your system for that hostname.

To get rid of this problem, the sophisticated way is to remove the entry from

vim ~/.ssh/known_host (you can use anything in place of vim)

delete the entire line which contains the hostname which is your pain point

hostname(192.168.1.123 for example) EDSA_key

It should work without restarting you system.

Not recommended

Otherwise the hard way around is by, removing all the contents of the file(truncating), never delete the file completely it may lead to some other problem and don't modify permission of the file also.

Sayan Biswas
  • 189
  • 1
  • 5
0

Remove the ssh cache using

ssh-keygen -R ipAdress

Ex:ssh-keygen -R 43.224.158.621

Hopefully this will work

Susampath
  • 706
  • 10
  • 13
-1

For windows go to this path

C:\Users\Dell\.ssh

& delete this file

known_hosts --> Delete

tipu sultan
  • 187
  • 3
  • 5