Results 1 to 5 of 5
It is recommended that you print out these instructions if you intend to use them without access to a computer where you can read them directly from this site.
Reset ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 01-30-2006 #1forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,733
HowTo: Recover (reset) Root Password
It is recommended that you print out these instructions if you intend to use them without access to a computer where you can read them directly from this site.
Reset Root Password - Easy Method:
Probably the simplest way to solve a forgotten root password problem is to boot your system in the single-user mode.
For LILO users:
If you are using LILO, at the LILO boot prompt (graphical LILO users can press Ctrl-x to exit the graphical screen and go to the boot: prompt), and then enter:
This will make you the "root" user without asking for a password. Once the system has booted, you can change the root password using the password command:Code:linux single
For GRUB users:Code:passwd
boot machine
when the GRUB menu appears, use arrow keys to choose OS to be booted
press letter "e'' on the keyboard to enter edit mode
use arrow keys to select the kernel line for kernel to be booted
press "e" to edit line
go to end of line and type "single" (without quotes) as a separate word
press ESC key to exit the edit mode
press "b" to boot into single user mode
Reset Root Password - Not As Easy Method:
If the easy method doesn't work on your machine, another way to solve the "lost root password" problem is to boot your computer from your Linux Installation CD/DVD, or from a live-CD/DVD such as Knoppix.
Boot with the live-disk then go to a terminal and su to root (no password is required) then issue the following commands (be sure to replace each /sda1 with your own root partition device):
Once you are into your system /etc directory, you can use a text editor (vim, nano, pico, etc.) to edit the /etc/shadow file where the password is stored. Various information about root and user accounts is kept in this plain-text file but we are only concerned with the password portion.Code:mount -o dev,rw /mnt/sda1 cd /mnt/sda1/etc
For example, the /etc/shadow entry for the "root" account may look something like this:
Now, using your favorite editor (I'll use vim) delete the password hash. For this example, the password is in green text and is all those characters between the 1st and 2nd colons.Code:root:$1$aB7mx0Licb$CTbs2RQrfPHkz5Vna0.fnz8H68tB.:10852:0:99999:7:::
After you've edited this field, it should look like this:Code:vim shadow
Now save the file and change back to the root directory and unmount the system root partition (don't forget to change the /sda1) as follows:Code:root::10852:0:99999:7:::
Now reboot the computer.Code:cd / umount /mnt/sda1
Once the computer has booted and you're at the login prompt, type "root" and when asked for the password just press ENTER (entering no password). After a successful login, you need to set the new password for root using the following command:
Code:passwd
Note that I've tested both the above methods on my machines but please keep in mind that neither of them will work on every machine.
Reset Forgotten or Lost "User" Password:
If a regular user forgets his/her password, the root user can easily reset the user's password. For this example, the username will be "bob".
Enter (as root):
This will prompt for a new password for the user "bob".Code:passwd bob
====================================
Hopefully, this HowTo will serve as a good reminder of the old saying that "anyone having physical access to a machine owns that machine". Please feel free to post any additions and/or corrections and I'll be happy to add them to the HowTo.
Thanks!
ozarLast edited by oz; 12-03-2008 at 06:38 PM. Reason: edit section titles
- 01-30-2006 #2
ozar, good howto, there is another method which can be used to change the root password without editing /etc/shadow file.
Boot from a livecd as normal.
Mount the linux partition in rw mode e.g. mount -o rw /dev/hda1 /mnt/hda1
In terminal become root i.e. su -
Chroot into the partition i.e. : chroot /mnt/hda1 /bin/bash
then change password with passwd command i.e. passwd
this will change the entry in /etc/shadow for the root password.Life is complex, it has a real part and an imaginary part.
- 01-30-2006 #3forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,733
Hi, Alex

Yeah, I've used that method (or a similar one) in the past, but to be honest, I couldn't remember how I did it so didn't include it in the howto.
Thanks for submitting it because neither of the first two options will work for every machine, but the third option might be just the fix for someone.
- 01-30-2006 #4Linux Enthusiast
- Join Date
- Aug 2005
- Location
- Hell
- Posts
- 514
For GRUB, to enter single-user mode you press the "A" key for append mode, and then add " single" to the end of the line.
- 06-09-2008 #5
OK ... try at grub menu, select first entry and add init=/bin/bash to the kernel line and boot the system. This should drop you at a bash shell where you can type passwd and set the root password. Once you have done this reboot the system using reboot ... let us know how it goes

Ed: this method works for openSUSE 10.3 ... single user mode still prompts for the root password ... ozar could this method be added to the how-to as its still a relatively easy method ?
Moderator Edit: Done
Last edited by oz; 06-20-2008 at 10:40 PM. Reason: copied post to this thread


3Likes

