How to reset root password in Linux in 3 minutes

In this article, you will learn, How to reset your root user password in Linux in 3 minutes

There are many passwords to store and remember. Sometimes system admins forgot their system root user password. And this creates a lot of trouble. In this tutorial, I will guide you, how to reset the forgotten root user password in just three minutes. This tutorial is valid for Red Hat Enterprise Linux, Fedora, and CentOS Enterprise Linux, or CentOS for short.

If your system hard disk is encrypted with LUKS, you would have to provide the LUKS password key when you got a prompt, but if you don’t have set this LUKS, then there is no problem. I have tested this process in CenOS 6.5/7/8 and RHEL 7/8 and Fedora 15 and later versions. You may also like to read how to boot into an emergency mode?.

Resetting your forgotten root user password in Linux

If your system is running (on) then, first you have to turn it off. And after turning it off, you can follow the below steps.

Step 1: 

Turn on your computer

Step 2: 

When you see the GRUB2 boot menu, it means boot option, something like the below picture, press letter e to edit the boot menu.

Linux bootloader screen

Step 3: You will see the screen like the below picture, you have to look for the line which is starting with linux16.

Step 4: At the end of this line, you have to type rd.break and then press Ctrl + x
Also, you can look at the below picture for getting help.

reset forgot root password

Step 5: If you have followed all the steps correctly, then you will see the screen which will start switch_root:/#
When you see the above lines, you can start typing the below commands in series

reset forgot root password
mount -o remount,rw /sysroot
chroot /sysroot

Also, now to reset the password use the below command.

passwd root

Now you can type a new password for the root user.
retype the password

Using the below command, you will relabel the files which you have modified during the password change.

touch /.autorelabel
exit
exit

and now you can wait, it will take sometime and then, it will automatically reboot the machine. that’s all.

Conclusion

In this tutorial, you learned, How to reset your root user password in Linux in 3 minutes. This process is very easy as you saw. But, sometimes it’s harder when you are working in a production environment because you have to shut down the system, and then you can reset the password. So, I always recommend that you create a sudo user with at least password reset capability. I hope you understand but, if you have any questions, you can ask in the comment section.

Also, you may like to read further,

3 Comments

  1. Thanks, its informative, can you share some article with Docker and Ansible stuff’s .

  2. I reset the password for my root account using this article. It works for me and it takes only 2.5 minutes. thanks Sahil sir.

Leave a Reply