How to enable login as a root user on AWS Instance

ubuntu

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 ubuntu 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 sudocommand.

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″
AmritMatti

I’m the owner of “DevOpsTechy.online” and been in the industry for almost 5 years. What I’ve noticed particularly about the industry is that it reacts slowly to the rapidly changing world of technology. I’ve done my best to introduce new technology into the community with the hopes that more technology can be utilized to serve our customers. I’m going to educate and at times demonstrate that technology can help businesses innovate and thrive. Throwing in a little bit of fun and entertainment couldn’t hurt right?

AmritMatti

I’m the owner of “DevOpsTechy.online” and been in the industry for almost 5 years. What I’ve noticed particularly about the industry is that it reacts slowly to the rapidly changing world of technology. I’ve done my best to introduce new technology into the community with the hopes that more technology can be utilized to serve our customers. I’m going to educate and at times demonstrate that technology can help businesses innovate and thrive. Throwing in a little bit of fun and entertainment couldn’t hurt right?

View all posts by AmritMatti →

Leave a Reply

Your email address will not be published. Required fields are marked *