DEV Community

Cover image for How to fix the git warning "ECDSA host key for 'github.com' differs from the key for the IP address '140.82.113.3'"
Jared Nielsen
Jared Nielsen

Posted on

How to fix the git warning "ECDSA host key for 'github.com' differs from the key for the IP address '140.82.113.3'"

If GitHub's recent RSA SSH host key update causes your system to throw this error:

Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.113.3'
Enter fullscreen mode Exit fullscreen mode

The solution is a quick fix. The next lines of the error will read something like this:

Offending key for IP in ~/.ssh/known_hosts:X
Matching host key in ~/.ssh/known_hosts:Y
Are you sure you want to continue connecting (yes/no)?
Enter fullscreen mode Exit fullscreen mode

Where X is the line number containing the IP address we want to remove. So...

Run the following command:

vi ~/.ssh/known_hosts
Enter fullscreen mode Exit fullscreen mode

And ⬇️ to line X and run the following to delete the line and exit vi:

dd
:x
Enter fullscreen mode Exit fullscreen mode

Voila!

Top comments (3)

Collapse
 
drmercer profile image
Dan Mercer

You can also do sed -e "Xd" ~/.ssh/known_hosts to delete line X (the line number from above). A little bit easier than using Vim. 😅

Collapse
 
xtofl profile image
xtofl

Would you need the in-place argument? sed -i "Xd" ~/.ssh/known_hosts?

Collapse
 
xtofl profile image
xtofl

While this does the trick, it bypasses the tools that are offered by the ssh package.

The ssh package has a tool called ssh-keygen with a 'remove' subcommand -R.

So you should be using ssh-keygen -R 140.82.113.3.


Warning: the ECDSA host key for 'github.com' differs from
the key for the IP address '140.82.121.3'
Offending key for IP in /home/xtofl/.ssh/known_hosts:12
Matching host key in /home/xtofl/ssh/known_hosts:58
Are you sure you want to continue connecting (yes/no)?
^C


09:28 $ ssh-keygen -R 140.82.121.3
# Host 140.82.121.3 found: line 12
/home/xtofl/.ssh/known_hosts updated.
Original contents retained as /home/xtofl/.ssh/known_hosts.old
Enter fullscreen mode Exit fullscreen mode