If you’re currently using Amazon EC2 Instance you certainly don’t have full-root access to your virtual machine. As I know that AWS EC2 instance is not allowing full root acces after OS installation finished. Usually AWS EC2 provide default user access, like centos, debian, ubuntu, ec2-user, but it depending on your distribution system. So it’s make you more difficulty if you don’t know on how to gains full-root access on your AWS EC2 machine.

Well, on this today guide I will show you on how to enable full root access on AWS EC2 instance. This tutorial should work for serveral Linux distribution system like RHEL/Fedroa/CentOS, and Debian/Ubuntu. So simply follow this tutorial to get full root access on your EC2 VM.

REQUIREMENTS

* Server IPv4 Address
* Your Login Credentials
* PuTTy or Gnome Terminal

1.) Login to Your AWS EC2 Instance via Terminal with private key (.pem file / .ppk) which you have generated previously.

$ ssh ec2-user@server_IPv4_address

You can change ec2-user to ubuntu if you’re currently using Ubuntu LTS server or centos if your vm using centos 7/8, instead of Amazon Linux AMI 2.

2.) Simply run the following command to get full root access

$ sudo su root

“OR”

$ sudo i

3.) Let’s Create Your First Root Password

$ passwd root

4.) Change some variables on sshd_config file

$ nano /etc/ssh/sshd_config

And then set some ssh config variable to yes, as you can see bellow.

$ PermitRootLogin yes
$ StrictModes yes
$ PasswordAuthentication yes

Or simply run this single command:

$ sudo sed -i 's/prohibit-password/yes/' /etc/ssh/sshd_config

5.) Then, you must copy SSH key from AWS-EC2 user directory to root directory.

$ cp ~ec2-user/.ssh/authorized_keys ~root/.ssh/authorized_keys

Please not if you are using ubuntu or centos simply change to the following command.

$ cp ~ubuntu/.ssh/authorized_keys ~root/.ssh/authorized_keys
$ cp ~centos/.ssh/authorized_keys ~root/.ssh/authorized_keys

6.) Next, we need to edit /etc/cloud/cloud.cfg file and change the following variable to this value:

$ nano /etc/cloud/cloud.cfg

*For Debian/Ubuntu:

$ disable_root false

OR

$ disable_root: false

For Fedora/RHEL/CentOS:

$ disable_root: 0
$ ssh_pwauth: 0

7.) Restart SSH Service

After that, don’t forget to restart SSH service.

$ service ssh restart (Ubuntu)
$ service sshd restart (centOS)

So it’s very easy to learn on it, you just having relax time to perform this task.

LEAVE A REPLY

Please enter your comment!
Please enter your name here