Learn how to recover forgotten root password in Linux RHEL. Step by step procedure to reset root password by booting system in single user mode.
There are many times when we set 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 console or reboot system, they most of times forgot root password to login.
So it becomes extremely important to have one more account with root privileges on 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 its becomes necessary to know how to recover forgotten root password.
Root password can not be recovered once forgotten! It can only be reset to new value! Now question is if you dont know root password how will you reset it when you wont bale to login in first place. Answer is single user mode!
Yes, to reset root password (when you forgot it) you need to boot server into single user mode. Why single user mode? Simple single user mode boots and present you 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 power button and halt the boot process by pressing any key when you see press any key to interrupt boot message on console.
If you have installed more than one OS on your system, you will see more than one entries in 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 password if not then just press enter. After entering password or pressing enter, you will be presented with next screen:
Here, press “e” key to edit the selected entry. You will be presented with kernel line selection screen like below.
Select 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 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 previous screen. Select kernel and press “b” to boot this edited kernel. Thats it! your server is booting in single user mode which will give you access to system without need of login.
Observe that, you haven’t asked for 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 system. But you need to go through all above steps again and remove single user mode entry you made previously. Or else 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 forgotten root password to new one. Keep new password in safe place and dont forget again! Since forgetting takes your almost 10-20 mins of downtime.