0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

サーバを立て直した後、ssh接続できなくなった

Last updated at Posted at 2022-08-06

はじめに

サーバーを立て直した際に、フィンガプリントが異なるということでssh接続が出来なくなったため、記事にまとめました。

フィンガープリントとは、指紋のようなものです。
以下のサイトが参考になりました。
https://www.videor.co.jp/digestplus/market/2021/02/41277.html

初めてSSH接続したサーバーの場合、フィンガープリントが「/home/ユーザ名/.ssh/known_hosts」ファイルに記録されます。
次回、同じIPアドレスのサーバーでssh接続する場合は、フィンガープリントが一致しているかチェックされます。

前回投稿した以下の記事に、フィンガープリントについて記載したため参考にしてください
https://qiita.com/gama1234/items/3ad5f698784af3fd39d1

エラーの内容

前回のIPアドレスを使用して、サーバーを立て直した際にフィンガープリントが変わることにより、
SSH接続した際に、以下のエラーが出てssh接続出来ませんでした。

test@DESKTOP-0S2U0NI:~$ ssh 192.168.0.3
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:4IzCPtqvmBKGorb9UGdSOXMOBt1MyoH6akql4Ck10mk.
Please contact your system administrator.
Add correct host key in /home/test/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/test/.ssh/known_hosts:2
  remove with:
  ssh-keygen -f "/home/test/.ssh/known_hosts" -R "192.168.0.3"
ECDSA host key for 192.168.0.3 has changed and you have requested strict checking.
Host key verification failed.

解決方法

本課題のエラーの対応方法は、以下のQiitaの記事が参考になりました。有難うございました。
https://qiita.com/hnw/items/0eeee62ce403b8d6a23c

ssh-keygen -Rのコマンドは、指定したホストに属する鍵を全て取り除く様です。
以下のサイトを参考にしました。
https://atmarkit.itmedia.co.jp/ait/articles/1908/02/news015.html

「ssh-keygen -R ipアドレス」を実行し、ホストに属する鍵を全て取り除きました。

test@DESKTOP-0S2U0NI:~/.ssh$ ssh-keygen -R 192.168.0.3
# Host 192.168.0.3 found: line 2
/home/test/.ssh/known_hosts updated.
Original contents retained as /home/test/.ssh/known_hosts.old

問題なくSSH接続出来ました。

test@DESKTOP-0S2U0NI:~/.ssh$ ssh root@192.168.0.3
The authenticity of host '192.168.0.3 (192.168.0.3)' can't be established.
ECDSA key fingerprint is SHA256:4IzCPtqvmBKGorb9UGdSOXMOBt1MyoH6akql4Ck10mk.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.0.3' (ECDSA) to the list of known hosts.
root@192.168.0.3's password:
Last login: Sat Aug  6 10:35:48 2022

まとめ

実業務でサーバーの移行により、IPアドレスが同じでサーバーが異なる際に本課題のエラーが出ました。
事前に知識として対応方法を知ることで、業務で役に立つと思いました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?