Debian Etch wouldn't let me into single user mode without the root password. I booted from the Debian CD and tried the rescue mode... didn't quite understand how to do it. So I had to take an alternate route.
I understand that it is not the safest method, but it works. I booted into Ubuntu on my machine (I have Debian and Ubuntu running on the same machine; you can use a live CD instead) and modified passwd and shadow files on the root partition of Debian. Here are the steps.- Boot into Ubuntu (or any other Linux) on the machine.
- Become super-user.
su
password: top-secret
- Create a mount point.
mkdir /mnt/deb
- Mount the Debian root partition.
mount /dev/hdXY /mnt/deb #X and Y identify the Debian root partition. - Open passwd and shadow files with an editor.
gedit /mnt/deb/etc/passwd /mnt/deb/etc/shadow
- Delete the password field for root in /etc/passwd (delete the x in second field)and comment out the root line in /etc/shadow (add a # at the start of the root record).
- Now save the two files and reboot into Debian.
- Hit Ctrl+Alt+F1 for the first terminal.
- Enter root at the login prompt. You will be greeted by a root prompt (#). Type passwd and create a new password for root. Now, return to GUI by hitting Ctrl+Alt+F7.
- But this method leaves encrypted password in the world readable passwd file. So, I cut-and-pasted the second field in /etc/passwd over the same field in /etc/shadow; and then restored x back to its place in the passwd file.