was https://www.serverwatch.com/tutorials/article.php/3818511
Juliet Kemp
Sometimes you wind up taking over a machine for which the root password has been lost. Here are a couple of solutions.
-
Reboot (hard reboot by pulling the power cable if rebooting requires the root password), and hit
e
to edit the boot line when you get to the GRUB menu. Scroll down to the line that starts with kernel, then hite
again to edit it, add 'single' to the end, and hit Enter to accept. Nowb
to boot and eventually you'll be dumped into a root shell. From here typepasswd
to change the root password.- [from me]: Don't ever pull the power cord on your computer! Hold the power button down for four seconds, or find a switch at the back of your case at the power supply. If all else fails, turn your power bar switch off. You do use a surge-protecting power bar or UPS for your computer, right?
-
Some systems require the root password to boot into 'single' mode. In this case, try editing the grub boot line to add
init=/bin/bash
to the end of the kernel line. This will boot you into a very basic system, using the bash shell instead of init. You may have to mount the root partition read/write:
mount -no remount,rw /
Then use passwd
to reset the password.
-
If grub is protected, try booting from a LiveCD or USB stick. Open a root shell, and use
fdisk -l
to show the available disk partitions. Mount the root partition with
mount -o,rw /dev/hda1 /mnt
Check it's the right directory with ls /mnt
, then change into that as your root directory:
chroot /mnt
Now use passwd
as before.
NOTE: It's important to bear in mind that all of these are also potential security risks if people have physical access to your machines.
Last updated 2020-10-12 at 00:32:16