ItecSoftware Logo

How to recover a lost Linux root password

Written by Peter Gilg on - like this:
recover 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.

Grub boot loader screen

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.

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

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.

Listed in Linux, Useful Stuff

Tags: forgot root password, grub, recover password, root password, single-user mode

Leave a Reply