Enable Root access for the Linux EC2 Instances

Vignesh A Sathiyanantham
2 min readFeb 20, 2021

--

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_configPermitRootLogin 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.cfgdisable_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

Originally published at Vignesh A S — Blog.

--

--

Vignesh A Sathiyanantham
Vignesh A Sathiyanantham

Written by Vignesh A Sathiyanantham

Decade of experience in building product related to private datacenter and public cloud #Java #AWS #VMware #Python

No responses yet