如何解决“Offending key in ~/.ssh/known_hosts” file

来源:互联网 发布:ubuntu查看根目录 编辑:程序博客网 时间:2024/04/30 13:02

如何解决“Offending key in ~/.ssh/known_hosts” file

Remove the offending ssh key

Following error will be displayed when the remote host key changes (after you’ve connected earlier with a valid remote host key).


[javascript] view plaincopy
  1. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  
  2. @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @  
  3. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  
  4. IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!  
  5. Someone could be eavesdropping on you right now (man-in-the-middle attack)!  
  6. It is also possible that the RSA host key has just been changed.  
  7. The fingerprint for the RSA key sent by the remote host is  
  8. a7:a8:f2:97:94:33:58:b7:9d:bc:e0:a6:6b:f7:0a:29.  
  9. Please contact your system administrator.  
  10. Add correct host key in /home/ramesh/.ssh/known_hosts to get rid of this message.  
  11. Offending key in /home/ramesh/.ssh/known_hosts: 6  
  12. Permission denied (publickey,password).  

You have to remove the key to proceed further. Use the following command to remove the offending key.

  1. # sed -i '6d' ~/.ssh/known_hosts  

Note: Change the 6d according to the line number shown.

If your sed does not have -i option, use perl or use some editor to remove the offending key.

Perl solution:


  1. # perl -pi -e 's/\Q$_// if ($. == 6);' ~/.ssh/known_hosts  

Note: Change the line number from 6 to appropriate line number.