reset root password in rhel

How to Reset Root Password in RHEL/CentOS/Fedora Linux

Sometimes you may need to reset root password in RHEL/CentOS/Fedora Linux because you forgot password or for security purposes. In this article, we will look at how to reset root password in RHEL/CentOS/Fedora Linux. If you have an active account with sudo privileges you can easily do this with the following command

$ sudo passwd root

You will be asked for new password and confirmation. However, if you don’t have sudo access for local user then follow the steps below to change root password via GRUB boot menu.


How to Reset Root Password in RHEL/CentOS/Fedora Linux

Here are the steps to reset root password in RHEL/CentOS/Fedora.

1. Boot RHEL/CentOS/Fedora

Boot/Reboot your RHEL/Fedora/CentOS Linux. When you see the boot process, press ‘e’ key to interrupt boot process and load the boot menu.

You will be able to see kernel parameters that you need to modify to reset root password. Here are the default parameters.

Navigate your cursor to the line starting with ‘linux…’ and press ctrl+e to edit it. Navigate your cursor to ‘ro crash’ and replace it with ‘ro break’ as shown below. This is a very important step so please do it very carefully.

Check the above change to ensure that it is correct. Only then press Ctrl+X to start your system.

You will be taken to a shell, where you need to remount your disk in read-write mode, with the following command.

mount -o remount,rw /sysroot

Change to sysroot folder to reset root password.

chroot /sysroot

Reset root password with passwd command.

passwd

You will be asked for new password and confirmation. Once you have reset password just enable relabeling on reboot and exit console.

touch /.autorelabel
exit
exit

Here’s a summary of the past steps.

The system will resume normal boot and prompt you for username and password.

That’s it. You have successfully reset root password in RHEL/CentOS/Fedora Linux. The key step in all this is to carefully edit kernel parameter from ‘ro crash’ to ‘ro break’, and switching to /sysroot folder after remounting disk.

The above steps can be used to reset password on most RHEL versions. As you can see, it is a little complicated so it is advisable to create a local user with sudo privileges to be able to easily reset root password, without having to change kernel parameters, as it can make the system unstable, if not done properly.

Also read:

How to Use Auto Indent in VI Editor
How to Setup LogAnalyzer with Rsyslog and MySQL
How to Setup Rsyslog with MySQL
How to Upload & Download Files from FTP in Linux
How to Delete Files Older Than X Days in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *