Reset Linux Root Password

Option #1

  1. At the beginning of bootup, when the GRUB or LILO screen pauses to choose the kernel, edit the line to add this to the end (after the kernel specification):  init=/bin/bash
  2. Because the root filesystem will probably mount read-only (preventing a password change), add the following to the end of the kernel line (after "bash") to boot the system read-write: rw
  3. Boot
  4. Type passwd to change the password.   (if you forgot to add rw above, after the system boots you can remount the root filesystem as read-write with this command: mount -o remount,rw / )
  5. Reboot

Option #2

            Do the same as the above, except replace "init=/bin/bash" with "S" or "single" or "init 1"
            However, the system may prompt you for the root password.
            ( S and single = single user mode. init 1 = runlevel 1, which is single user mode)

 

Option #3

  1. Insert a LiveCD (Knoppix, Gentoo, PCLinuxOS), or put the hard drive into another Linux computer.
  2. Boot from the LiveCD, or boot into the other computer's Linux OS.   Login as root.
  3. Mount the hard drive that has the filesystem containing the root password you want to change:

                mount -o dev,rw /mnt/hda1 [or other device name]

  1. Use a text editor (like nano or vi) to edit the /etc/shadow file on the mounted drive.*
  2. On the line starting with root, delete the all the characters of the password "hash."  The password hash lives between the first and second colons.
  3. Save the file, unmount the mounted hard drive, and reboot.
  4. Login as root, with a blank password.  Then you can reset the password with the passwd command.

 * Some Linux systems may store the password has in the less-secure /etc/passwd file. 

 

Option #4

  1. Follow steps 1-3 in Option #3 above.
  2. Copy the "urandom" file so that passwd can use the blowfish algorithm to generate the password: cp -a /dev/urandom /mnt/hda1/dev/urandom
  3. Issue a "change root" command to make your mounted hard drive as your operating environment: chroot /mnt/hda1 /bin/bash
  4. Now change the password with:  passwd
  5. Reboot

Powered by Linux