Reset the Root Password on Slackware

If you've installed Slackware and forgotten the root password, it's easy to reset. In fact, passwords on any OS are easy to reset as long as you have physical access to the computer and install media. Slackware is no exception.

This also will be an introduction to the concept of chroot, which is a great command and concept to understand, so whether or not you actually need to reset a password just this moment, you might find this post informative.

Here is how to reset a forgotten root password:

  1. Boot your computer from the install media.
  2. When the initial Slackware-install boot screen appears, hit Return as you normally would.
  3. Accept the keymap (or change it if you do not use the default North American keyboard)
  4. Login, as usual, as root with no password (you will not be prompted for a password, since this is an install disc).

At this point, you're sitting in the normal shell for the Slackware installer. Here is where the terminology gets strange; you are here to reset the root password, but remember that the beginning point of a UNIX filesystem is also called “root”. It is a completely different concept from being a “root user”. So remember that there is the root location and a root user, and we're talking about both of those things here. I will be very explicit as to which “root” concept I am talking about from this point on.

Right now, your computer thinks the root [the location] point of your hard drive is the DVD drive because you booted from the DVD. It makes sense that the computer sees that as its root location.

What you need to do is re-assign what the computer sees as its root [the location] partition so that any commands you give it applies to a new root [the location]. That is, you want to take the computer and yank the rug out from under its feet, and switch it out for the actual physical hard drive upon which you have installed Slackware-with-a-forgotten-password. And you don't want the computer to notice.

That's precisely what chroot was written to do.

  1. Mount the physical harddrive to some place. Since this is an environment running entirely in RAM, it doesn't matter where; just create a new directory and mount it there:
# mkdir /rescue
# mount /dev/sda1 /rescue
  1. Change directory into the mounted hard drive and make it the new root [location] for the system.
# cd /rescue
# chroot .
  1. Now, as far as your computer knows, you are running your normal everyday Slackware system just as if you'd booted off of it in the first place. The computer, having been lied to with chroot, has no memory that you booted off of a DVD. This means that if you run the passwd command to change your password, instead of changing the password for the DVD environment, it will change the password for your hard drive's root [the person] user.

Do that now:

# passwd
  1. Enter a new passphrase for your root identity, and then reboot.

When you reboot, be sure to eject the DVD so that your computer does't boot off of it again. Once your system is up, log in as root with your new passphrase and get back to work.

R S Q