Technology Weblog

Howto reset root password for a linux machine

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 !


15 Responses to “Howto reset root password for a linux machine”

  1. nice and usefull info, asking permission to copy and paste in my blog at

  2. yes you can plz give me link back if you like 🙂

  3. Does this always work? Atleast with me it works only on all Fedora 7 comps and Ubuntu comps whose root passwords are not set.

  4. Yes, this should work on all.

  5. In my machine, it doesn’t go to the # prompt. Instead it asks for root password. I get a message like this “Enter root password for maintenance: “.
    Any clues why this is happening and what can I do about it?
    Since I was not the only one using my machine, is it possible that someone changed the fstab?

  6. “Enter root password for maintenance: “.

    The file system might be corrupted. You may need to perform a fsck (file system check )

  7. I have tried it on several Ubuntu 7.10 and 8.04.. It does not work on my comp in which the user set the root password..( ie. Not the default one )..

  8. If you’ve set a root password and forgotten it, you could always boot into a live cd, chroot into your on-disk install and change the password from there… not as simple mind you but should get around the problem

  9. @nitinr0cks
    No, it’s probably not corrupted. Some distro require root password to enter runlevel 1, openSUSE for example.

    Try to change the ‘single’ parameter with ‘init=/bin/bash’.

  10. That works great.

    To note on step 7 for Fedora Core 9, enter passwd then enter. Will get a message you are changing the root password, afterward enter the new password.

    Thanks for posting this.

  11. thx man, very nice.

  12. I needed a little more steps to reset the password, some of you who may get stuck may need this.
    Reset linux box password.

  13. there you go – its easy

  14. I don’t have a grub. My boot manager is LILO. How to reset Root password on it?

  15. worked like a charm almost verbatim exactly

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: