YURU_DB

OracleDB / AOJ(python)

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

OS再インストール後、rootでssh接続しようとしたらタイトルと同様の以下エラーが発生

Macintosh:~ user$ ssh root@153.126.166.XXX
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 RSA key sent by the remote host is
SHA256:pxpVhv6+gGUJNQfWBfZwngxutEy/61/3SYaMO1VVAIs.
Please contact your system administrator.
Add correct host key in /Users/user/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/user/.ssh/known_hosts:14
RSA host key for 153.126.166.XXX has changed and you have requested strict checking.
Host key verification failed.
Macintosh:~ user$

調べてみると、OS再インストールによりサーバーの公開鍵が変わったことが原因。 再インストールが悪いというわけではなく、クライアント側でOS再インストール前のフィンガープリントを保存しており クライアント側情報とサーバー側情報で不整合なので発生している。

というわけで以下コマンドでクライアント側のフィンガープリント削除を実行。

Macintosh:~ user$ ssh-keygen -R 153.126.166.XXX
# Host 153.126.166.XXX found: line 14
/Users/user/.ssh/known_hosts updated.
Original contents retained as /Users/user/.ssh/known_hosts.old

以下の対話が表示されるがyesで無事rootログインできました。

Macintosh:~ user$ ssh root@153.126.166.XXX
The authenticity of host '153.126.166.XXX (153.126.166.XXX)' can't be established.
RSA key fingerprint is SHA256:pxpVhv6+gGUJNQfWBfZwngxutEy/61/3SYaMO1VVAIs.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '153.126.166.XXX' (RSA) to the list of known hosts.
root@153.126.166.XXX's password: 

SAKURA Internet [Virtual Private Server SERVICE]

[root@ik1-319-19652 ~]# 

追記 あんまスマートじゃないけど、以下の方法でknown_hosts削除しちゃうのもアリ

rm -rf ~/.ssh/known_hosts