How to recover a lost Linux root password
Forgot your root password? Nice going. What now? Reinstall the machine from ground up? Sadly enough, I’ve seen this happening all too often while it’s surprisingly easy to change the password knowing the correct procedure. While this doesn’t work in all cases (like if you secured your machine with a GRUB password and forgot that as well), but here’s the procedure in case of a CentOS Linux machine.
Recover Linux root password in Cent OS
Start off by rebooting your system. At the GRUB boot loader screen, move the highlighted entry with the arrow keys to interrupt the boot process. While the current boot entry is highlighted, press E and you can edit the kernel line.
Boot into Single User mode
Use the arrow key to highlight the line that starts with kernel
, and press E to edit the kernel parameters. When you get to the screen below, append the number 1
at the end of the line. This will enable you to boot into single-user mode.
Next press Enter, then B, and the kernel will boot up into single-user mode. Once there you can run the passwd
command, changing the password for user root
Change root password in Single User mode
prod-093# passwd New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully
Next time you boot up, use your newly created password to login.
Now it’s time to get some therapy and maybe even a massage. You’ve earned it after this nightmare.