Reset Lost Root Password – CentOS 7


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



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 


2. Find the line starting with linux16.

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


3. Press CTRL-X to enter single user mode 



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