Say you work in an office where more than one person provisions and/or has root access on the Linux servers. Every now and then you’ll probably run into a situation where you don’t know the root password. Now if you have another account that can “sudo”, you’re not completely dead in the water. You can log in with that account, then use elevated privileges to change the root password.
So let’s get started!
First, I should note that this method works with the GRUB bootloader. Although it has not been tested with other bootloaders, it may work.
1. Reboot the server. At the “GRUB Loading” screen hold down the SHIFT key to bring up the boot menu.
2. Select <kernel version> (recovery mode), then “Drop to root shell menu prompt” on the next screen.
Note: If “recovery mode” is not available
- Select the generic kernel and press “e” to edit the entry
- On the following screen select the “kernel” entry and press “e” again
- Scroll to the end of the line and add “rw init=/bin/bash”, then press Enter
- On the next screen, press “b” to boot using modified kernel parameters
3. The server will now boot to the root prompt. Type the following command to change the password: passwd <username> (e.g. to change the password for the root user, type “passwd root“)
4. Enter the new password, then enter it again to confirm it.
5. All done. Reboot the system with the “reboot” command.
Note: If you get a message that reads “passwd: Authentication token lock busy”, run the following command: mount -o remount,rw /
Then use the commands in step 3 to change the password.
Good luck!
Leave a Reply