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:

root:(HIDDEN):0:0:root:/root:/bin/tcsh
to
root::0:0:root:/root:/bin/tcsh

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.

To reset your root password in Linux without knowing it already, do this:

  1. Reboot
  2. At the LILO prompt (on x86 - the silo prompt is more applicable on Suns, or the yaboot prompt on ppc), type
    linux init=/bin/sh
  3. Wait for a shell prompt to appear. Type
    mount -o rw,remount /
  4. Type
    passwd root
  5. Enter a new password
  6. Type
    umount /
  7. Type
    sync
    (probably unnecessary, but fun)
  8. Type
    sync
    (certainly unnecessary, but certain traditions have to be followed)
  9. Type
    sync
    (completely and utterly unnecessary, except that not doing so guarantees that everything will go horribly wrong)
  10. Reboot
  11. Be happy
  12. Don't be stupid enough to do that again, you clot

Much the same can be done with most other unices. init=/bin/sh is preferable under Linux because some distributions (such as Debian) require you to know the root password in order to get the shell prompt in single user mode.

Log in or registerto write something here or to contact authors.