How to reset the Forgotten root password in AWS-EC2 Instance

Published: 9 October 2019
root password

It is often found challenging or sometimes difficult to reset the forgotten root password in the AWS system. Administrators, and analysts have their task cut out already with deployments or overseeing smooth running of IT systems. The password reset methods in the AWS system is bit difficult and professionals find it time consuming to address this challenge.

Here are the steps to resolve it:

1. Power Off the instance (Example project Server)

2. Note the Ebs Volume info (dev/sda1), and detach the volume from server.

3. Create the new instance (dummy Instance) with minimal configuration, it must be a same region as example project server.

4. Attach the Example project Root volume to New instance (dummy instance),

5. Login to dummy instance,

6. Check the volumes using following command – “lsblk”

7. Mount the Example project root volume to dummy instance,

# create directory : mkdir /mnt
# mount the volume : mount /dev/sda /mnt

8. Create the new user in dummy instance and set the password.

# Create user : useradd Sennovate
# set password: passwd Sennovate (Note down the Password)

9. Get the sennovate user encryption password from  /etc/shadows.

(Like: $1$iJjm1IwS$0HA2.5f8d6Cpq6XQTv5KU.:17780:0:99999:7:::)

10. Go to the mount location and open the shadows file,

# cd /mnt/etc/
# vi shadows then change the encryption value to Example project user.(encryption value:$1$iJjm1IwS$0HA2.5f8d6Cpq6XQTv5KU.:17780:0:99999:7:::)

11. After changing the value just un-mount the volume from dummy Instance.

# for un-mount : un-mount /dev/sda

12. Detach the volume from dummy server and attach to Example project server

13. Now you can login to the instance as usual.

No worries if you lost the root password. By implementing the above procedure, it’s just a walk in the park where you can easily reset a lost or forgotten root password in AWS EC instance.

Related Posts