LoginSignup
5
4

More than 5 years have passed since last update.

AmazonLinux SSH パスワードログイン許可

Posted at

AmazonLinuxは初期状態ではSSHでパスワードログインできない

いくつもインスタンスを作成した経験からですが、インスタンス作成時に必ずSSHの設定がリセットされるようです。例えば、SSHでパスワードログインを許可していたインスタンスから作成したAMIがあります。そのAMIから作成したインスタンスにSSHでパスワードログインしようとしても、SSHの設定が初期化されているため、一度ec2−userアカウントと作成した鍵でログインする必要があります。

設定手順

  • SSH設定ファイルのバックアップ
# cp /etc/ssh/sshd_config  ~/sshd_config_yyyymmdd
  • 差分がないことを確認
# diff /etc/ssh/sshd_config  ~/sshd_config_yyyymmdd
  • SSH設定ファイルの編集
# vi /etc/ssh/sshd_config

変更前PasswordAuthentication yes
変更後PasswordAuthentication no

  • 編集後の設定ファイルとバックアップの差分確認。 修正箇所のみに差分があること
# diff /etc/ssh/sshd_config  ~/sshd_config_yyyymmdd
75c75
< PasswordAuthentication yes
---
> PasswordAuthentication no
  • SSH設定ファイルの構文テスト。エラーがないこと
# sshd -t
  • SSHの再起動。
# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]

※失敗したらどうなるかは試したくても試せないです。

  • 別ターミナルからログインできること。上記の設定中に開いたコンソールを閉じると二度とログインできなくなる可能性があるので、別ターミナルから実施します。
ssh ec2-user@xx.xx.xx.xx -i private.key

以上。

5
4
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
5
4