Reset the root password on a RHEL/CentOS version 7 or later system, from Grub bootloader.
- First, connect to server console using monitor locally, or via Virtual Machine remote console.
- Reboot the server, as soon as the bootloader comes up with the OS selection screen, quickly tap the up and down arrows up and down to pause the boot selection counter.
- Select the line OS/kernel you want to boot into, and press '
e
' to edit the edit the grub bootloader options. - Go to the line that refers to the kernel:
- On RHEL/CentOS 7, the line starts with 'linux16'.
- On RHEL/Centos 8x, and Fedora the line starts with '
Linux
'. - Type 'rd.break' at the end of the above line. Thes changes are temporary, will be automatically removed after reboot.
- Press Ctrl-X to boot from the current kernel with edited options.
- Now server will boot into rescue mode. and the root is mounted in read-only mode.
- Now we need to remount the root partition in read-write mode.
- Execute mount -o remount,rw /sysroot to mount root partition in read-write mode.
- Now run below command to change system root to new root location. "chroot /sysroot"
- Now you have full root access to the linux system. Use passwd command to change password for root or any users.
- Use "cat /etc/passwd" to list all users in the server.
- once the password reset is completed, create a .autorelabel file to allow changes in SELinux . "touch /.autorelabel"
- Now type exit and reboot the system to boot into normal mode.
0 Comments