SSHログインで接続エラーとなった場合の対応

raspberry-pi

UbuntuのOSアップデート後、PC(windows)からサーバにSSH接続すると接続エラーとなった時の対応メモ

PC(Windows)のコンソールからssh-keygenを使って鍵を一度削除し再接続すると復旧する。

1.ログイン不可の状態

Host key verification failed ということで接続ができない

PS C:\Users\papanda925> ssh xxx.xxx.xxx.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 ECDSA key sent by the remote host is
******:**********************************************
Please contact your system administrator.
Add correct host key in C:\\Users\\papanda925/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in C:\\Users\\papanda925/.ssh/known_hosts:2
Host key for xxx.xxx.xxx.xxx has changed and you have requested strict checking.
Host key verification failed.
PS C:\Users\papanda925> ssh papanda925@192.168.10.150
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
******:**********************************************
Please contact your system administrator.
Add correct host key in C:\\Users\\papanda925/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in C:\\Users\\papanda925/.ssh/known_hosts:2
Host key for xxx.xxx.xxx.xxx has changed and you have requested strict checking.
Host key verification failed.

2.ssh-keygen -Rで鍵を削除

ssh-keygen -R サーバのIP で 鍵を known_hosts  から削除する。

PS C:\Users\papanda925> ssh-keygen -R xxx.xxx.xxx.xxx
# Host xxx.xxx.xxx.xxx found: line 2
C:\Users\papanda925/.ssh/known_hosts updated.
Original contents retained as C:\Users\papanda925/.ssh/known_hosts.old

3.再チャレンジ(接続可能)

ssh-keygen -R後にssh で再接続すると、初回登録時の動き(鍵の登録等)をして、ログインが可能となる。

PS C:\Users\papanda925> ssh papanda925@xxx.xxx.xxx.xxx
The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established.

~~~~~
~~~~~

papanda925@xxx.xxx.xxx.xxx's password:
Welcome to Ubuntu 22.10 (GNU/Linux 5.19.0-1004-raspi aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0のアップデートはすぐに適用されます。

*** System restart required ***

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

    4.参考

    他にもこういった事象になられた方がいるみたい、先人に感謝です。

    sshログインできない時すごく焦った。

    SSHで『Host key verification failed』と出てログインできない時の対処法 (affi-sapo-sv.com)

    「SSHホスト鍵が変わってるよ!」と怒られたときの対処 – Qiita

    ライセンス:本記事のテキスト/コードは特記なき限り CC BY 4.0 です。引用の際は出典URL(本ページ)を明記してください。
    利用ポリシー もご参照ください。

    コメント

    タイトルとURLをコピーしました