Recover FreeBSD root access when you forgot the password

Losing your root password is not necessarily the end of the world. Single User Mode offers the solution to a lost root password.

Using a decent password management system can help ensure that you can use unique, strong passwords for everything that needs a password, without having to worry about forgetting or losing your passwords. No matter how many passwords are stored in your password management system, you only need to recall the password you use to access the password manager; it does the rest of the remembering for you. Many password manager options exist, including my current favorite, pwsafe — which can be used as a keyboard shortcut driven X tool with the application of just a little ingenuity.

There are times you may not want to use a password management system to store a password, however. Some might argue against the wisdom of storing the root password for a Unix system within a password management tool run on that system, for instance. If you are bothered by the prospect of storing the root password in your password manager's database, you still have to contend with the task of remembering that password on your own.

We use passwords very regularly in our day-to-day computing lives, such as when logging into any of dozens of Websites we may visit daily or even many times a day. Because of that, chances are good that anyone using a password management system to store passwords will have to type in the password for that password manager quite often. As a result, the possibility of forgetting that password (short of blunt force trauma to the head) is effectively nonexistent for the majority of us. In cases such as maintaining a FreeBSD file server that basically never needs maintenance or rebooting, however, the system's root password might be much more easily forgotten. Months at a time between uses of a password is not a schedule designed to engrave it on the forefront of one's brain.

Combining rare usage of the root password with a reluctance to store it in a password manager could be a recipe for disaster. It would be a tremendous shame to have to reinstall an OS just because of a failure to remember a password. Luckily, there are often ways around this problem. In FreeBSD, you should be able to recover root access when you have forgotten the root password by following these steps:

  1. Restart the system.
  2. At the boot: prompt, enter boot -s to enter Single User Mode.
  3. When asked what shell to use, press the Enter key.
  4. Because the root filesystem will be mounted read-only by default, you will need to remount it using the mount -ruw / command to give yourself read/write access.
  5. Run mount -a to remount all filesystems specified in the /etc/fstab file.
  6. Run passwd root to set a new root password.
  7. Run exit to continue booting normally.

This time, you should consider how you intend to avoid losing the root password . . . again.


Chad Perrin is an IT consultant, developer, and freelance professional writer. He holds both Microsoft and CompTIA certifications and is a graduate of two IT industry trade schools.

Editor's Picks