Reset Lost Root Password – CentOS 7

Issue:

I lost the password for my CentOS 7 virtual machine in my cloud VDC. 

 

Resolution:

To reset the root password we will firstly need to boot into single user mode. Use the following steps:

1)  Reboot the VM. During startup press "e" in grub menu 

centos_reset_1

2. Find the line starting with linux16.

    Replace "ro" with "rw init=/sysroot/bin/sh"

centos_reset_2

3. Press CTRL-X to enter single user mode 

centos_reset_5

 

4.  Access the system

# chroot /sysroot

5. Change password

# passwd root

Note: You may need the following command if SE Linux is enabled:

touch /.autorelabel

6. Exit 

# exit

7. Reboot the system

# reboot