このセクションでは、Amazon Linux(EC2)の root ユーザーのパスワード設定について紹介していきます。

Amazon Linux の OS で EC2 インスタンスを立ち上げた当初は、root ユーザーのパスワードは設定されておりません。そのため、EC2 インスタンスに接続してログインできれば誰でもパスワード無しで root ユーザーになれる状態になっています。 

[ec2-user@ip-172-31-4-114 ~]$ su -

Last login: Tue Aug 22 04:45:04 UTC 2023 on pts/2
[root@ip-172-31-4-114 ~]# 

パスワード無しで簡単に root ユーザーでログインできるのはセキュリティ上好ましくないため、root ユーザーのパスワードを設定していきます。

[ec2-user@ip-172-31-4-114 ~]$ sudo passwd root
Changing password for user root.
New password:        ← rootユーザーのパスワードを入力
Retype new password:     ← 再度、パスワードを入力
passwd: all authentication tokens updated successfully.
[ec2-user@ip-172-31-4-114 ~]$

パスワードを設定した後は、root ユーザーでのログインにパスワードを求められるようになります。

[ec2-user@ip-172-31-4-114 ~]$ su -
Password: 
Last login: Tue Aug 22 04:57:09 UTC 2023 on pts/2
[root@ip-172-31-4-114 ~]#