There are a number of different ways to do root password recovery on a Linux system. Different distributions make it easier than others. You must be physically in front of the system.
For Red Hat and Mandrake:
Boot from your first install CD and as the very first screen comes up hit F2 and type: rescue ( For RedHat “linux rescue” ) and the computer will boot in rescue mode. Select “mount the existing partitions” and go to the shell/console prompt.
For SUSE:
Boot from your first install CD and press F1 at the first screen, then choose “Rescue System” from the menu and at the prompt type “root” ( you do not need a password )
For other distro’s:
Boot from the first install CD ( or any Live CD like Knoppix ) and at the boot prompt type: linux single
It will boot in “single user mode” and you will get an odd looking prompt like “sh-2.09#”
Alternative,
With the most Live and Rescue CDs you can also just boot in the live version, mount the partition and, as root, make changes to the files indicated below:
# cd /etc
To reset password, we need to change two files; “passwd” and “shadow”
# vim passwd
find root:x:0:0:root:/root:/bin/bash and,
Make it:
root::0:0:root:/root:/bin/bash
Save and exit the file.
# vim shadow
The first line is a long line of characters, just make it:
root:::: ( four colons ! )
Now you can reboot your computer. Log in as normal user, open a console and type:
$ su
# passwd
New password:
Retype new password:
Now, you can log in as a root user with the new password.

Related Articles: