Published January 06, 2018 by

Enable login as a root user on AWS Instance

Please Note this article is only for information and practice. Please don't do this until you have any specific and valid reason. Because it's a big security hole by opening direct root access of server in the cloud.

When we create an instance in AWS, it will set the default login user name to connect an instance through SSH. Generally when we try to access server on AWS server as a user 'root'. It will give a message like below. It means you can not able to log in with directly using the root account, and first, you have to log in as a default user according to your OS and then use 'sudo su –' to get root user access.

Enable log in as a root user on AWS:

I have an ubuntu server so I will take an example of Ubuntu.

Login to your server with ubuntu user and then switch to root user using the sudo command.

login as: ubuntu

ubuntu@ip: sudo su -

Now edit /root/.ssh/authorized_keys file. You will get a more extra code with your key.

# vim /root/.ssh/authorized_keys

Remove the underlined text from an authorized_keys file and your key should look like this.

Save it and tries to log in as a root user.

You will be successfully logged in to the server as a root user directly.

How to revert

If you want to revert this and disable root login so just insert below code into /root/.ssh/authorized_keys file before your key.

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10"