Aside from the aforementioned ways to retrieve your 'root' account, there are some others not mentioned here for dealing with the loss of a root password:
Boot Disk... the importance of a boot disk is paramount. Although, if you just want reset your root password, the type of boot disk isn't as important. It needs to be able to do the following:
- Mount the partion where your 'passwd' file is stored
- Understand the filesystem of that partition
- include a text editor or be able to run a text editor from your installation
I'll use a scenario of a co-worker of mine. He forgot the root password on his box. We could have used the run-level technique described above, but we didn't. Instead we just booted of a Slackware CD we had lying around, mounted his root partion and used the venerable vi to edit the /etc/passwd (/etc/shadow on some systems) entry for root, changing this:
That will not work on all *nix systems, but it will work on most. Then, when you login fron the console as root, it (usually) will not ask you for a password, and you can then run 'passwd' from the command line and re-enter another root password. This is very dependant of the OS in question, but it worked on my co-workers BSD box.
And there is a second way that I would recommend myself: Don't bother with root passwords!
Use SSH... the setup depends on which SSH implimentation your are using, but they can all be given what are known as 'authorized keys'; this means that you can, using SSH, log as root using your SSH keypair. Then, if you're feeling suicidal, you can 'star out' your root account (though I wouldn't reccomend it). In this scenario, then, all you need to remember is your SSH passphrase and do an "ssh -l root localhost" and either run 'passwd' or edit the /etc/passwd file as described above.