Home / Web Development / VPS / How to Enable Root account and Password Login on AWS EC2
enable-root-password-login-on-ec2

How to Enable Root account and Password Login on AWS EC2

Amazon EC2 instances come with root account disabled by default. They also use a PEM key file to authorize user so the use of passwords are also disabled. While these are excellent practices in terms of security. Some people prefer to have these enabled for many reasons. One of them being use of a control panel such as Virtualmin.

The thing with these control panels are that you can’t use PEM key files to login. So you need to be able to use passwords to login. And majority of them uses Ubuntu’s root user as the master admin. While you can create another account with root privileges, you need to be logged in to the control panel as root user to do it. So if you’re planning to use a control panel on your AWS EC2 instance, you need to be able to use passwords to login. In that case you can follow below instructions to prepare your instance and enable root account. Please note that these instructions are for Ubuntu 16.04 instances. But it might work on other Ubuntu versions as well.

Login to your EC2 instance with standard user account. This could be ubuntu or ec2-user depending on the image you deployed on your instance. Once inside, switch to root account by giving this command.

sudo -i

Now open the SSH configuration file with nano text editor.

nano /etc/ssh/sshd_config

Enable Root Account on EC2 Instance

Search for following line within the file (Ctrl+W),

PermitRootLogin

Now change no to yes. File should look like this after the change.

Root account will be enabled on your EC2 instance after service restart. But you still can’t login to root account because you don’t have password logins enabled on your server. You can enable it by following below instructions.

Enable Password login on EC2 Instance

Now search for following line within the configuration file,

PasswordAuthentication no

Change no to yes. File should look like this after the change.

Now close the file and reload SSH service.

service sshd reload

Password login should be enabled now. You can now set a password for root account. Use following command on Putty to do it.

passwd

Root account is now enabled on your EC2 instance and you can login to it using the password you set above.

namecheap namecheap

About Tharindu Kumara

Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me. send me a message on Fiverr.

Leave a Reply