はじめに
EC2インスタンスにSSH接続ができない状況があったので、その一覧を以下に記述します。
内容
【インスタンスを作り直してやる処理】
- インスタンスにアタッチされているEBSのスナップショットを作りバックアップ
- 作業用インスタンスを作成する
- 作業用インスタンスに、対象インスタンスのEBSをアタッチとマウント
※参考:https://qiita.com/keisuke_kimura/items/a7c79f4ab3a954a41780
【「/etc/ssh/sshd_config」のAllowUsersを設定してやる処理】
- 「less /var/log/secure」で「not allowed because not listed in AllowUsers」ログを確認
- 「sudo less /etc/ssh/sshd_config | grep "AllowUsers"」でAllowUsersを確認
- viでAllowUsersを消す、もしくは追加したいユーザを追加する
※参考:https://qiita.com/toshihirock/items/897776cfa620c3231737
【homeディレクトリのパーミッションが所有ユーザー以外に書き込み権限があるとアクセスが拒否対処】
- 「less /var/log/secure」で「Authentication refused: bad ownership or modes for directory /home/hoge」ログを確認
- StrictModesをnoに設定
$ vim /etc/ssh/sshd_config
StrictModes no
※参考:http://teketeke55.hatenablog.com/entry/2012/02/02/165238
【「Failed to add the host to the list of known hosts」といわれる場合の対処】
- オーナー変更
sudo chown username /Users/username/.ssh/known_hosts
- 権限変更
sudo chmod 600 /Users/username/.ssh/known_hosts