Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > Linux Resources > Linux Tutorials, HOWTO's & Reference Material
Reload this Page HowTo: Recover Root (and user) Password
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Tutorials, HOWTO's & Reference Material A useful collection of tutorials, guides and reviews compiled here for easy reference purposes.

 
 
Thread Tools Display Modes
Old 01-30-2006   #1 (permalink)
ozar
Super Moderator
 
Join Date: May 2004
Location: Arch Linux
Posts: 8,253
Lightbulb HowTo: Recover Root (and user) 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.

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:

Code:
linux single
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:
passwd
GRUB users will follow basically the same steps, except that the GRUB boot loader doesn't have a default boot prompt, but you can choose "e'' when the menu displays to edit the boot parameters. Just select the kernel line for the kernel you want to boot. Go to the end of that line and type "single" as a separate word, then press ENTER to exit the edit mode. Once back at the GRUB screen, 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, or from a live-CD such as Knoppix.

Using Knoppix, boot the live-CD then go to a terminal and su to root (no password is required) then issue the following commands (be sure to replace each /hda1 with your own root partition device):

Code:
mount -o dev,rw /mnt/hda1
	
cd /mnt/hda1/etc
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.

For example, the /etc/shadow entry for the "root" account may look something like this:

Code:
root:$1$aB7mx0Licb$CTbs2RQrfPHkz5Vna0.fnz8H68tB.:10852:0:99999:7:::
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:
vim shadow
After you've edited this field, it should look like this:

Code:
root::10852:0:99999:7:::
Now save the file and change back to the root directory and unmount the system root partition (don't forget to change the /hda1) as follows:

Code:
cd /
umount /mnt/hda1
Now reboot the computer.

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):

Code:
passwd bob
This will prompt for a new password for the user "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!

ozar

Last edited by ozar : 06-26-2006 at 04:21 PM. Reason: edit section titles
ozar is offline  
Old 01-30-2006   #2 (permalink)
AlexK
Linux Guru
 
AlexK's Avatar
 
Join Date: Feb 2005
Location: Earth
Posts: 3,381
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.
AlexK is offline  
Old 01-30-2006   #3 (permalink)
ozar
Super Moderator
 
Join Date: May 2004
Location: Arch Linux
Posts: 8,253
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.
ozar is offline  
Old 01-30-2006   #4 (permalink)
spoon!
Linux Enthusiast
 
Join Date: Aug 2005
Location: Hell
Posts: 515
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.
spoon! is offline  
Old 4 Weeks Ago   #5 (permalink)
Jonathan183
Linux Engineer
 
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,280
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 ozar : 2 Weeks Ago at 10:40 PM. Reason: copied post to this thread
Jonathan183 is offline  
 


Currently Active Users Viewing This Thread: 3 (0 members and 3 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 06:19 AM.

Powered by vBulletin 3.6.8 ©2000 - 2007, content relevant URLs by vBSEO, Property of Core Root.

Content Relevant URLs by vBSEO 3.0.0