LoginSignup
16
15

More than 5 years have passed since last update.

EC2のAmazonLinuxでrootログイン可能にする(AMI設定まで)

Last updated at Posted at 2015-12-04

EC2のAmazonLinuxはデフォルトでrootログインを禁止しているため
一旦 ec2-userでログインしてから毎回 sudo su - でrootに変更しないといけない。

個人での運用だと面倒なので、rootログインを可能に設定した。
またAMI化したあとに、新しいec2インスタンスを立ち上げると設定が戻ってしまうので、それの対応もする。


・rootユーザーに切り替える
sudo su -


・設定変更
vi /etc/ssh/sshd_config
PermitRootLogin forced-commands-only

PermitRootLogin without-password


・ec2-userの公開鍵をそのままコピーします。
mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys_bak
cp -f /home/ec2-user/.ssh/authorized_keys /root/.ssh/authorized_keys
service sshd reload


・この状態でAMIを作成して、新しいインスタンスを立てると
 rootでログインできない状態に戻る(authorized_keysが変更される)
 のでcloud-initも変更します。
vi /etc/cloud/cloud.cfg
disable_root: false

disable_root: true


16
15
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
16
15