How To Reset/Break Root User Password In RHEL 7..!!
STEP-1 : If your Linux system is currently running, reboot it. If it is not yet running, start it up. At the boot menu, press the ‘e’ key to edit the first boot entry.
STEP-2 : 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, as shown below and Press “Ctrl+x” to boot with these options. This will boot to the initramfs prompt with a root shell.
STEP-3 : At this stage, the root file system is mounted in read only mode to /sysroot and must be remounted with read/write (rw) permissions in order for us to actually make any changes. This is done with the ‘mount -o remount,rw /sysroot’ command.
STEP-4 : Once the file system has been remounted, change into a chroot so that /sysroot is used as the root of the file system. This is required so that any further commands we run will be in regards to /sysroot. This is done by running ‘chroot /sysroot’.
STEP-5 : From here the root password can be reset with the ‘passwd’ command.
STEP-6 : If you’re not using SELinux, you could reboot at this point and everything would be fine, however by default CentOS/RHEL 7 use SELinux in enforcing mode, so we need to fix the context of the /etc/shadow file. This is because when the ‘passwd’ command is run, it creates a new /etc/shadow file. As SELinux is not running in this mode the file is created with no SELinux contexts, which can cause problems when we reboot. Create the /.autorelabel command using ‘touch’.Creating this file will automatically perform a relabel of all files on next boot.
STEP-7 : Enter the ‘exit’ command twice, the first one will exit the chroot environment while the second will exit the initramfs root shell and reboot the system.
Once the reboot is completed you will be able to use the root account with your new password.
No comments: