78

I've done tons of search and tested different solutions, but gain no success!

When I want to push my codes, I receive the following error:

Warning: the ECDSA host key for 'git.mywebsite.ir' differs from the key for the IP address '164.138.23.11'
Offending key for IP in /home/alireza/.ssh/known_hosts:10
Matching host key in /home/alireza/.ssh/known_hosts:1
Are you sure you want to continue connecting (yes/no)? yes

What should I do to remove this message every time I push my changes? Any idea?

key list

3 Answers 3

147

It says:

Offending key for IP in /home/alireza/.ssh/known_hosts:10

So for some reason you have to delete 10-th line in known_hosts.

Run this command to delete 10-th line in known_hosts:

sed -i '10d' ~/.ssh/known_hosts

Or use ssh-keygen

ssh-keygen -R git.mywebsite.ir

Quote from man

 -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).
6
  • 8
    ssh-keygen -R git.mywebsite.ir solved my problem.
    – Alireza
    Apr 26, 2014 at 10:57
  • 1
    didn't work for me, it keeps on asking question. Sep 10, 2014 at 19:45
  • 3
    sed -i '1d' ~/.ssh/known_hosts or manually removing the line no. did work for me Nov 30, 2016 at 8:52
  • 1
    If you're running this in Terminal on a Mac, you'll have to do sed -i '' '10d' ~/.ssh/known_hosts to avoid the "extra characters at the end of l command" error because it requires an extension to be specified.
    – Luke
    May 15, 2018 at 16:51
  • 3
    if you want to remove the key based on ip address: ssh-keygen -R [ipaddress]:port. example of removing key for 192.168.0.1 on port 3456: ssh-keygen -R [192.168.0.1]:3456 Jun 5, 2018 at 9:02
6

When I got the messages:

Offending key for IP in /home/myusername/.ssh/known_hosts:12

Notice the line number - in my case - 12

So open 'known_hosts' file and delete the 12-th row.

For me this solved the problem.

P.s. Notice if you cannot find the .ssh folder - the .ssh folder is hidden and in order to see it from the file manager - you have to "Show hidden files and folders". In Linux Mint (and possible in your distro too) when in the file manager - there is a shortcut to show/hide hidden folders -> Ctrl+H

Cheers

0

You have to edit your known_hosts file (located in ~/.ssh/known_hosts) and remove an entry asociated with this address.

3
  • This IP address does not exist in known_hosts file.
    – Alireza
    Apr 26, 2014 at 9:54
  • 1
    That's right, there is probably an entry with git.mywebsite.ir URL and another IP address. You should remove this line from known_hosts and then new IP adress will be associated with this host name.
    – kulak
    Apr 26, 2014 at 10:06
  • There is nothing as my site URL in known_hosts file. I cannot even find git in the file. Could you take a look at the picture above?
    – Alireza
    Apr 26, 2014 at 10:14

You must log in to answer this question.

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