Learn how to recover forgotten root password in Linux RHEL. Step by step procedure to reset the root password by booting system in single-user mode.
There are many times when we set the root password too complex and later on forgot it. Many people used to work on consoles with no timeout values. In such cases, when they logged out of the console or reboot system, they most of the times forgot the root password to log in.
So it becomes extremely important to have one more account with root privileges on the system. Normally in corporate environments, they do keep such 2-3 accounts so that forgetting root password shouldn’t stop operations. But like in test environments or labs sometimes these practice is not followed and it becomes necessary to know how to recover forgotten root password.
A root password can not be recovered once forgotten! It can only be reset to new value! Now the question is if you don’t know the root password how will you reset it when you won’t able to login in the first place. The answer is the single-user mode!
Yes, to reset root password (when you forgot it) you need to boot the server into single-user mode. Why single user mode? Simple single user mode boots and present your root prompt without any requirement to log in! Simple eh? So resetting forgotten root password follows simple steps :
- Edit boot kernel path with single-user mode parameter (GRUB)
- Boot kernel into single user mode
- Reset root password
- Get into normal multi-user run-level
Lets see all these steps below with screenshots :
1. Edit boot kernel path
Restart server with the power button and halt the boot process by pressing any key when you see press any key to interrupt boot message on the console.
If you have installed more than one OS on your system, you will see more than one entries in the above screen. Use arrow keys to select (highlight) your kernel. If your bootloader is protected with password then press “p” you will be asked for a password if not then just press enter. After entering the password or pressing enter, you will be presented with the next screen:
Here, press the “e” key to edit the selected entry. You will be presented with a kernel line selection screen like below.
Select the kernel line and press “e” again to edit that entry. Now on new screen append letter S or single at end of the line so instruct the kernel to boot into single-user mode.
2. Boot kernel into single user mode
After typing above entry, press ‘enter’ key to save and you will back to the previous screen. Select kernel and press “b” to boot this edited kernel. That’s it! your server is booting in a single-user mode which will give you access to the system without the need of login.
Observe that, you haven’t asked for a password, and you are presented with root prompt!
3. Reset root password
Do I have to write anything for it? You have a root prompt already! go change your root password like you normally do.
# passwd root Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully.
You can also check here that you are in single-user mode by checking run level with who command.
4. Get into multi user mode
You can do it by rebooting the system. But you need to go through all the above steps again and remove the single user mode entry you made previously. Or else the server will boot into again single-user mode.
Or you can simply type “init 3” to change your run-level from single to multi-user mode!
You have successfully reset the forgotten root password to a new one. Keep a new password in a safe place and don’t forget again! Since forgetting takes your almost 10-20 mins of downtime.
Share Your Comments & Feedback: