Reset forgotten RHEL 7 / CentOS 7 root password

Spread the love

We have got many changes in Red Hat Enterprise Linux 7 / CentOS 7 , one of the many changes GRUB 2 version. Reset the password through single user mode we are using in RHEL 5 and RHEL 6 version but here it will different from older versions.

Below is the new procedure to reset the root password , if we forget or lost our root password in RHEL 7.

Use below procedure carefully and mistake can make your machine unstable, first try l test machine on your own risk.

Show Forget root password and reboot the RHEL 7 server

Here I am showing the screen of trying to login through GUI in linux box and not getting success in login through GUI , same will be implement as command line interface.

GRUB 2 Edit Menu Option

In new version of GRUB , we will not use single-user mode , In GRUB2 we have the Rescue Mode / Emergency mode in new version of RHEL .

First start or reboot your machine and wait for GRUB 2 booting menu screen , it will show in image below and press “e” edit key to edit the grub 2 menu option after grub 2 loaded .

In editing GRUB 2 menu option go down and search “linux16” or “linuxefi” line using the arrow keys and go to the end of the line and add “rd.break” keyword .

After set rd.break key word in the end of the line press ctrl+x to boot or start the process.

Reset the root password

Now the Emergeny shell mode or rescue shell mode will available for reset the password .

First we will remount the sysroot file system in read and write mode and then use chroot to got into a chroot jait at /sysroot thorugh below commands .

# mount –o remount,rw /sysroot

# chroot /sysroot

Now we will git passwd command in the command line and press same password twice for reset root password.

In the Last point make sure that all unlabled files ( including shadow ) get relabled during boot with below command.

# touch /.autorelabel

Type exit two time s after run autoreleble activity. The first will exit the chroot jail and the second will exit the initramfs debug shell.

Find below all the commands history which we use to reset the password.

Now we have reset the password of root , after exit two times system will boot again and check given root credentials is working properly.