Bash
Mac
Linux
SSH

sshで接続を試みて、WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!の警告が出て接続できないときの対処法

概要

sshで接続を試みて、WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!の警告が出て接続できないときの対処法

事象

$ ssh -i ~/.ssh/id_rsa  user@example.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
SHA256:ThYwRCvgjDgQbLnt9dIYqv3KcjLQH95KA9zTnYj9ONU.
Please contact your system administrator.
Add correct host key in /Users/user/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/user/.ssh/known_hosts:55
ECDSA host key for example.com has changed and you have requested strict checking.
Host key verification failed.

対処法

~/.ssh/known_hosts の該当ホスト※の行を削除する。
※上の例だと、example.com

$ sed '/example.com/d'  /Users/user/.ssh/known_hosts > /Users/user/.ssh/known_hosts

以上で完了。

検証環境

  • MacOS Sierra バージョン 10.12.6
  • bash
  • iTerm