Mac OSX SSH Host key verification failed

I had a situation when I tried to SSH into one of the server, I received the error message below. Basically the server had generated a new SSH RSA host key that doesnt match with the old one stored on my MacBook Pro.

;

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 the RSA host key has just been changed.
 The fingerprint for the RSA key sent by the remote host is
 21:79:38:2d:2c:3d:f0:08:5d:e5:a6:a0:3f:af:a1:0a.
 Please contact your system administrator.
 Add correct host key in /Users/root/.ssh/known_hosts to get rid of this message.
 Offending key in /Users/root/.ssh/known_hosts:7
 RSA host key for x.x.x.x has changed and you have requested strict checking.
 Host key verification failed.

;

Mac OSX keeps SSH keys in /Users/root/.ssh directory, and this needs to be updated. The currently cached keys are in known_hosts file.

MBP:.ssh root$ cd /Users/root/.ssh
MBP:.ssh root$ ls
 known_hosts known_hosts.old

;

I can verify the content of know_hosts file, it only keeps the host name or IP Address and RSA keys.

MBP:.ssh root$ more known_hosts
 1.1.1.1 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCd+tMZOp9wAABMPQFBrJhW7IWH+zwNcbBzK2h7RI54nKAEBo6vm08YBXuql/En45kLI/O0NYd6Le0nfXU86kcwjdzFzV4B70XBCa7xv1qwoHu1Rnuy9DIKHpfQhlHSBVJRObcDk8UeVxe0YkwwP4F97nDa3cREfhiHWuDInSNrPw==
 2.2.2.2 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDDn06aNBc6LE4yW2AoEWu+WQj6d7xW3sQzUCmNiwU+pEWJcIM9cWm+smXnHdYwO7AU5tQwDpO5MLeAf5OvfQ7DshNams0aoFPVUD07ZiqN0yIw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3Xqo8HK6BC

;

Theoretically I can remove lines from this file but there is a command to remove the specific host RSA Key.

MBP:~ root$ ssh-keygen -R x.x.x.x
 /Users/root/.ssh/known_hosts updated.
 Original contents retained as /Users/root/.ssh/known_hosts.old

;

Now my RSA key for the remote server has been updated and key has been move to known_hosts.old file. And I can accept the new SSH RSA key.

MBP:~ root$ ssh -l root x.x.x.x
 The authenticity of host 'x.x.x.x (x.x.x.x)' can't be established.
 RSA key fingerprint is 21:79:38:2d:2c:3d:f0:08:5d:e5:a6:a0:3f:af:a1:0a.
 Are you sure you want to continue connecting (yes/no)? yes
 Warning: Permanently added 'x.x.x.x' (RSA) to the list of known hosts.
 Password:

;

   Send article as PDF   

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: