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)
nice and usefull info, asking permission to copy and paste in my blog at http://pinguinnest.wordpress.com
th34ng3l - February 29, 2008 at 2:07 am |
yes you can plz give me link back if you like 🙂
nitinr0cks - February 29, 2008 at 7:45 am |
Does this always work? Atleast with me it works only on all Fedora 7 comps and Ubuntu comps whose root passwords are not set.
Akhil Ravidas - May 13, 2008 at 2:39 pm |
Yes, this should work on all.
nitinr0cks - May 14, 2008 at 8:03 pm |
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?
rnik - July 2, 2008 at 4:18 am |
“Enter root password for maintenance: “.
The file system might be corrupted. You may need to perform a fsck (file system check )
nitinr0cks - July 3, 2008 at 12:13 am |
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 )..
Akhil Ravidas - July 16, 2008 at 8:20 am |
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
Andrew - July 24, 2008 at 8:42 am |
@nitinr0cks
No, it’s probably not corrupted. Some distro require root password to enter runlevel 1, openSUSE for example.
@rnik
Try to change the ‘single’ parameter with ‘init=/bin/bash’.
init7 - July 29, 2008 at 9:49 am |
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.
Hairman - November 6, 2008 at 2:29 am |
thx man, very nice.
chamal - December 2, 2008 at 5:07 am |
I needed a little more steps to reset the password, some of you who may get stuck may need this.
Reset linux box password.
digitalpbk - March 3, 2009 at 12:57 pm |
there you go – its easy
alim - May 25, 2009 at 8:18 pm |
I don’t have a grub. My boot manager is LILO. How to reset Root password on it?
Smoke - February 2, 2010 at 1:39 am |
worked like a charm almost verbatim exactly
spark - June 3, 2010 at 8:54 pm |