1
1

More than 3 years have passed since last update.

AWS EC2へsshでのログインができなくなった時の対処法

Posted at

結論

ec2インスタンスの再起動で解決できた

解決までの道のり

なんでログイン出来なくなった?

ec2内にアプリケーションをコンパイルしているときに、時間がかかりすぎて、途中でサーバーがタイムアウトになった。

再度sshログインしてみる

動かないままタイムアウトしてしまう。

とりあえずデバックモードで起動してみた

-vをつけると、デバックモード

% ssh 自分のkey -v
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/wadakazuma/.ssh/config
debug1: /Users/wadakazuma/.ssh/config line 1: Applying options for key_berlin_now_rsa
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to hogeip port 22.
debug1: Connection established.
debug1: identity file /Users/wadakazuma/.ssh/key_berlin_now_rsa type 0
debug1: identity file /Users/wadakazuma/.ssh/key_berlin_now_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1

なんかでた

kex_exchange_identification: read: Connection reset by peer

色々いじくってみた

・githubはssh接続できる

ssh -T git@github.com
Hi kazumawada! You've successfully authenticated, but GitHub does not provide shell access.

・ec2インスタンスを確認してみる参考

インスタンスのステータスチェック欄が赤くなっていた

インスタンスの接続性チェックに失敗しました(1/2のチェック)

インスタンスのステータスチェック
インスタンスの復旧

一旦用事があったので、2hほど離れたところ、インスタンスのステータスチェックに合格していた。(2/2)が、まだssh接続ができない。

とりあえずec2インスタンスを再起動してみる

sshログインできた

まとめ

僕の場合は、ec2インスタンスの再起動で解決できたのでこれ以上深追いはしませんが、他の方法はこことかみるといいかもしれません
https://dev.classmethod.jp/articles/ope20190813-ec2-trouble/
https://dev.classmethod.jp/articles/why-ec2-statuscheck-failed/
https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/monitoring-system-instance-status-check.html
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/automation-ec2rescue.html
https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/ec2-instance-recover.html

1
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
1
1