how-to-reset-redhat-7-os-root-password

If you have a redhat VM, take a snapshot of your virtual machine

Remember that this is the best practice in IT industry & we can revert to previous state if we face any big problem. Also taking clones & configuration backup are other method we use in IT industry.

Reboot the Virtual Machine

Press any key to stop boot process of the OS

Now select your kernal from boot menu and press ‘e’ to edit it

From the grub options, find the line that starts with “linux16” and go to the end of it. Enter ‘rd.break’ without quotes at the end of this line

Now Press “Ctrl+x” to boot with these saved options. This will load the root shell

In this mode the root file system is mounted in read only mode to /sysroot and must be remounted with read/write (rw) permissions because we are going to change root . To do this use command ‘mount -o remount,rw /sysroot’ command.

now change in to chroot jail. Then command we execute only apply to to sysroot. We must do this part and use below command.

‘chroot /sysroot’

Now reset password using ‘passwd’ command

now we need to create autorelabel because in this mode files will not be overwrite and /etc/shadow file will keep same and no changes will be applied to root password.

so create a autorelabel using ‘touch /.autorelabel’

now everything is fine and enter ‘exit’ twice and you will see logout on screen and vm will be rebooted

‘exit’

‘exit’

after reboot access your server using new password