Tag Archives: recover password

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.

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.

Grub boot loader screen

Grub boot loader screen

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.

Edit GRUB boot loader entry

Edit GRUB boot loader entry

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:

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.