How To Recover Linux Root User Password
Method No. 1:
The simplest way to recover from a lost password is to boot into single user mode.
If you are using LILO, at the LILO boot prompt (graphicalLILO users can press [Ctrl+X] to exit the graphical screen and go to the “boot:” prompt), enter:
linux single
This will make you the “root” user without asking for a password. Once the systemhas booted, you can change the root password using the password command:
passwd
The instructions for GRUB users are similar. Press [e] at the GRUB prompt to select boot parameters. Select theline for the kernel you want to boot, and go to the end of it. Add “single” as a separate word, and then press [ENTER] to exit the edit mode. Once back at the GRUB screen, press [b] to boot into singleuser mode.
Method No. 2:
If the above solution doesn't work for you, there is another option. Boot using a so called “Live CD” Linux distribution, such as Knoppix. For the purposes of this example,it will be assumed that the user is using Knoppix.
After booting up from the Knoppix CD, go to a terminal and su to root (no password is required). After your priviledges have been escalated,issue the following commands (be sure to replace each “/hda1” with your own root (‘/’) partition):
mount /dev/hda1 –t ext3 /mnt/hda1
cd /mnt/hda1/etc
Once you are into your system “/etc”directory, you can use a text-editor (such as 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-textfile, but we are only concerned with the password portion.
For example, the “/etc/shadow” entry for the “root” account may look something like this:root:$1$aB7mx0Licb$CTbs2RQrfPHkz5Vna0.fnz8H68tB.:/
10852:0:99999:7:::
(The ‘/’ indicates a line continuation)
Now, using your favorite editor (I’ll use nano) delete the password hash (the red text).
vim shadow
After you’ve edited this...
Regístrate para leer el documento completo.