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.
Now open the SSH configuration file with nano text editor.
Enable Root Account on EC2 Instance
Search for following line within the file (Ctrl+W),
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,
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.
Root account is now enabled on your EC2 instance and you can login to it using the password you set above.