Enable Root access for the Linux EC2 Instances

By default Amazon doesn’t enable root access to the users, This is a very important security best practise, admins, are supposed to connect using a secure key pair to log in as ec2-user ( Read more here about the default users in EC2 instances ) then user can run sudo command to obtain the elevated permissions.

User can enable the password authentication and log to EC2 instance using username and password, read here to learn more about enabling the password authentication for the amazon Linux and for Ubuntu server read here.

Note: Enabling the root user is not the best security practice but if any of your application needs root access, follow the below steps at your own risk

Create a root password

passwd root <password>

Enable the root login in the config file /etc/ssh/sshd_config

sudo nano /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes

Restart the SSH service

service sshd reload

Next step is Update your cloud config file

Edit the /etc/cloud/cloud.cfg file and change the value of disable_root to false

sudo nano /etc/cloud/cloud.cfg
disable_root false

The cloud cloud-init script or directives run only during the first boot cycle when an EC2 instance is launched. So when you create a AMI / Image and launch the new instance again from the Image, the image will retain the enabled root user

Also published on Medium.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.