Reset root password in Linux

Consider the case you forgot the root password of your Linux machine. Don’t panic !

You can reset it easily entering single user mode . Following are the run levels in linux.

Runlevel 0: Halt System – To shutdown the system
Runlevel 1: Single user mode
Runlevel 2: Basic multi user mode without NFS
Runlevel 3: Full multi user mode (text based)
Runlevel 4: unused
Runlevel 5: Multi user mode with Graphical User Interface
Runlevel 6: Reboot System

Following are the steps to reset password.

1. Restart the machine.

2. Wait for the “Grub loading” message to appear and, depending on your Linux distribution, get ready to hit either any key or the ESC key to enter the grub boot menu.

Grub loading, please wait ...
Press ESC to enter the menu

3. You will then get grub’s main menu which will display a list of available kernels. Use the arrow keys to scroll to your desired version of the kernel and then press e for “edit”.

Fedora Core (2.6.18-1.2239.fc5smp)
Fedora Core (2.6.18-1.2200.fc5smp)

4. The kernel’s boot menu will appear. Use the arrow keys to scroll to the “kernel” line and then press e for “edit”.

root (hd0,0) kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ initrd /initrd-2.6.18-1.2239.fc5smp.img

5. A grub edit prompt will appear. Use the arrow keys to move to the end of the line and add the word “single” to the end, separated by a space. Change

grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/

to following

grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ single

6. Press enter to save your changes, and then b for “boot”. 6. The system will continue to boot, but will go straight to the root # prompt without first asking for a username and password.

7. Now change the password using passwd command.

#passwd <give your new password>

8. Change the run-level using init command.

# init 5

( for Multi user mode with Graphical User Interface)

That’s it !

One thought on “Reset root password in Linux”

Leave a Reply