Option #1
- At the beginning of bootup, when the GRUB or LILO screen pauses to choose the kernel, edit the line to add this to the end (after the kernel specification): init=/bin/bash
- Because the root filesystem will probably mount read-only (preventing a password change), add the following to the end of the kernel line (after "bash") to boot the system read-write: rw
- Boot
- Type passwd to change the password. (if you forgot to add rw above, after the system boots you can remount the root filesystem as read-write with this command: mount -o remount,rw / )
- Reboot
Option #2
Do the same as the above, except replace "init=/bin/bash" with "S" or "single" or "init 1"
However, the system may prompt you for the root password.
( S and single = single user mode. init 1 = runlevel 1, which is single user mode)
Option #3
- Insert a LiveCD (Knoppix, Gentoo, PCLinuxOS), or put the hard drive into another Linux computer.
- Boot from the LiveCD, or boot into the other computer's Linux OS. Login as root.
- Mount the hard drive that has the filesystem containing the root password you want to change:
mount -o dev,rw /mnt/hda1 [or other device name]
- Use a text editor (like nano or vi) to edit the /etc/shadow file on the mounted drive.*
- On the line starting with root, delete the all the characters of the password "hash." The password hash lives between the first and second colons.
- Save the file, unmount the mounted hard drive, and reboot.
- Login as root, with a blank password. Then you can reset the password with the passwd command.
* Some Linux systems may store the password has in the less-secure /etc/passwd file.
Option #4
- Follow steps 1-3 in Option #3 above.
- Copy the "urandom" file so that passwd can use the blowfish algorithm to generate the password: cp -a /dev/urandom /mnt/hda1/dev/urandom
- Issue a "change root" command to make your mounted hard drive as your operating environment: chroot /mnt/hda1 /bin/bash
- Now change the password with: passwd
- Reboot