To reset linux root password and set it to "new passwd"

Step 1.

Reboot the VM

Step 2.

The VM will start rebooting and after the reboot process starts,
Go to rescue mode and start pressing 'e' key on your keyboard until you reach this screen.

Step 3.

The line which starts with the word "linux", go to the end of that line and add these two parameters: rd.break as shown below( Note- do'nt add any extra spaces).

press ctrl+x on your keyboard

Step 4.

use the command

switch_root:/# mount -o remount,rw /sysroot

switch_root:/# chroot /sysroot

it will switch into chroot jail

set the passwd for the root using the command :

sh-5.1# passwd root

Set the passwd as per instructed in the question.

Now, this step is crucial because we need to create a relabel file. If we skip this step, it could harm the VM's file system. So, to create the relabel file, proceed after you've set up the password.,

Note - When you break the grub boot process, SELinux does not load. When you run the passwd command in emergency mode, the /etc/shadow file gets clobbered and recreated and, because SELinux is not loaded, no SELinux context is applied to the file.

To fix this, you have to create the /.autorelabel file before you reboot the system.

$ man selinux

while in the manual use search option / and jus type the .auto and you will jump to the section where it is clearly stated that...

The best way to relabel the file system is to create the flag file /.autorelabel and reboot.

Process of relabelling the file system take the while so do not panic and just wait for the process completion.

use the command:

sh-5.1# touch /.autorelabel

Exit from the shell using exit command two times

Now, system will automatically reboot and relabel the SELinux contexts on files as neded (including on /etc/shadow). It may take some time but after the reboot is done, login as root with the new password you set.

Thank you !!

1
Subscribe to my newsletter

Read articles from SONAM KUMARI SINGH directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

SONAM KUMARI SINGH
SONAM KUMARI SINGH

SONAM here! Happy to see you here !! Tech enthusiast exploring new languages, deep into DevOps, with a spotlight on Linux & Containers. ๐Ÿ˜Š๐Ÿš€