/**/ How to Recover a Lost Root Password in Linux - Dextutor

How to Recover a Lost Root Password in Linux

At times we forget the root user password that we have set on our Linux machine. In this post, we will learn how to recover a lost root password in Linux. The procedure is most suitable of RedHat, Fedora and CentOS operating systems. Follow the below mentioned procedure:

Step 1: Reboot the machine and stop the countdown of the boot loader. To stop the countdown, press any key when the boot loader menu appears

Step 2: Use the arrow keys to highlight the default boot loader entry

Step 3: Press ‘e’ to edit

Step 4: Move the cursor to the line which starts with “Linux

Step 5: Press the “End” key to move to the end of this line and type “rd.break

How to Recover a Lost Root Password in Linux

Step 6: Now, Press Ctrl+x

Step 7: You will now see a “switch_root” prompt. At this prompt type the two below mentioned commands one after the other

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

How to Recover a Lost Root Password in Linux

Step 8: Now, the prompt will change. Next, use the passwd command to change the password

How to Recover a Lost Root Password in Linux

Step 9: Type the below command (Be very careful with spellings. There is dot (.) between / and ‘autorelabel’

# touch /.autorelabel

Step 10: Type exit twice

#exit
#exit

The system will run an SElinux relabel and reboot after doing the necessary updations. This might take sometime depending upon your system configuration, so be patient.

Congratulations! You have successfully reset the lost root user password.

Video on How to Recover a Lost Root Password in Linux

View this video see the entire process in a detailed manner.

Other Useful Links


Leave a Comment