We have got many changes in CentOS Stream or RHEL Versions from old versions . One of the many changes  GRUB 2 version . Every Linux system administrator should know the reset the lost root password .

Different method available to reset new root password by Live CD or edit shadow file or mount the root file system . Here we are doing not through any external media.

Below is procedure to reset  the root password , if we forget or lost our root password in CentOS Stream or RHEL and Alma-Linux Versions .

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 CentOS server

Below snapshot showing the  screen  user root try to login with last remembered password  and not getting success in login through GUI , same will be implement as command line interface.

GRUB 2  Edit Menu Option

Edit the kernel parameter line with Rescue Mode / Emergency maintenance mode.

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

In editing GRUB 2 menu option go down. Search “Linux” line using the up and down

arrow keys and go to the end of the line and add  “rd.break” keyword.

After setting rd.break keyword at the end of the line press ctrl+x  to boot or start the process.

Reset the root password

Now the Emergency shell mode or rescue shell mode will available for resetting the password.

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

 # mount –o remount,rw  /sysroot
 # chroot /sysroot 

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

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

 # touch /.autorelabel 

Type exit two times after running autoreleble activity. The first will exit the chroot jail and the second will exit the initramfs debug shell.

Find below all the command history that we use to reset the password.

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

I have got root screen  ..   🙂

By Sachin G

I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks! Sachin G Follow me on LinkedIn and x formerly twitter