How to recover from a lost root password
Newbies please note: this is a potentially dangerous operation that could damage your installation. Use it if you must, but understand that if the operation goes wrong, the system could be damaged. This could affect your precious data! A factor I love about Linux is one is rarely alone: if in doubt, seek help before proceeding.
This information was gleaned from the Forum, and is for the user who has an understanding of the Linux file system.
So you have lost or forgotten your root password. Woe is me! Do not fear, your forum members have provided a couple of methods to recover from this situation. Since Linux is all about choice, use the one that suits you.
Remember, there is no need to reload (reinstall) just because of a lost password.
Method 1:
Boot your machine using the LiveCD.
Once loaded, mount your original / (root) directory.
WARNING! Anything done as the root user can affect the usability of your system!
I usually will mount it as orig_root. Then from a terminal window:
cd /orig_root/etc su
using the LiveCD's root password (if you are using PCLinuxOS, this will be 'root'), then using you favorite text editor, edit the shadow file.
Example using nano, type:
nano shadow
this will load the shadow file and you should see something as follows. Yours may differ:
root:$1$8NFmV6tr$rT.INHxDBWn1VvU5gjGzi/:12209:0:99999:7:-1:-1:1074970543 bin:*:12187:0:99999:7::: daemon:*:12187:0:99999:7::: adm:*:12187:0:99999:7:::
we want to work with this line
root:$1$8NFmV6tr$rT.INHxDBWn1VvU5gjGzi/:12209:0:99999:7:-1:-1:1074970543
In this example, this is your encrypted password:
$1$8NFmV6tr$rT.INHxDBWn1VvU5gjGzi/
Remove this encrypted password. DO NOT remove the ":" before or after the encrypted password. After removing that portion of your line it should look something like below. Note: your may have different information.
root::12209:0:99999:7:-1:-1:1074970543
In nano, pressing Ctrl and x will prompt you to save the file. After saving the file, reboot your machine without the LiveCD.
Now your machine has no root password. To add your new root password to your system open a terminal window and type in "passwd root" (without the quotes) and press the enter key. You will be prompted for a new root password. When you type it in it will not be displayed. After entering it, press return. It will then prompt you to enter it again (again it will not be displayed when entering it.) After typing it in, press enter, and now you have a new root password.
Method 2:
Booting into single user mode from GRUB
When grub comes up hit escape. Click "ok" when it states you are leaving graphical mode. Highlight your boot entry, usually the first one. Press "e" to edit. This will highlight the first line (yours may look different):
kernel (hd0,0)/boot/vmlinuz-2.6.22.10.tex1.lgc BOOT_IMAGE=2.6.22.10.tex1.lgc root=/dev/hda1 acpi=on resume=/dev/hda5 splash=verbose vga=794
Append it so it reads (by adding 'single' to the end of the line:
kernel (hd0,0)/boot/vmlinuz-2.6.22.10.tex1.lgc BOOT_IMAGE=2.6.22.10.tex1.lgc root=/dev/hda1 acpi=on resume=/dev/hda5 splash=verbose vga=794 single
Press enter. Press "b" to boot in single user mode. You should now see this:
sh-3.1#
Type passwd and press enter. You will be asked for the new password and to retype it. After it accepts the password it will return to the prompt. Type reboot and press enter. You are now back in business.
Method 3:
Booting into single user mode from Lilo
When the Lilo screen shows up (the one where you can select which operating system to boot) press the Esc button. This will bring up a boot prompt. Type pclinuxos 1 and press enter.
PCLinuxOS means that you want to boot pclinuxos, the 1 means runlevel 1, i.e., single user mode. This will boot to a root# prompt (without asking you for the password) so you can now change it with the passwd command to whatever you want.
Type passwd and press enter. You will be asked for the new password and to retype it. After it accepts the password it will return to the prompt. Type reboot and press enter.
Have Fun!