How to Reset the Root Password

If you have forgotten your Linux system root password it can be reset either by taking action at boot or via a live Linux CD.

Reset Root Password from Grub Menu

To reset the root password the boot sequence will be interrupted with a change made to the status of the boot drive. This will enable access to run the passwd command from the command line applying the new password.

Start by restarting the computer

When the screen shows the GRUB boot loader list of boot options click on the e key to edit the grub configuration.

The change to be made is to put the boot into read-write mode.

Look for the line beginning with linux, similar to the below:

linux /boot/vmlinuz-5.3.0-1-amd64 root=UUID=b1386117-8b4b-4d54-acfb-4fedcef5ff01 ro quiet

Edit this line changing the text ro to rw. also append with the text init=/bin/bash. Thus giving:

linux /boot/vmlinuz-5.3.0-1-amd64 root=UUID=b1386117-8b4b-4d54-acfb-4fedcef5ff01 rw quiet init=/bin/bash

Press f10 to continue booting into single user mode. A command prompt will be shown with the user set as root.

The filesystem is to be mounted in read-write mode. To mount the hard drive type

mount -n -o remount, rw /

The password can now be changed using the password command. Simply type passwd and enter the updated password twice when prompted.

With the password set the computer can be rebooted. The changes made previously to the boot menu are a one off, no action will be needed regards these. To restart the computer type

exec /sbin/init

Reset Root Password with Live CD

The root password can also be modified using a Linux live CD.

Boot the computer from the live CD.

Note you may need to edit the BIOS of the computer to set the CD/DVD player as the primary boot device.

Start a command prompt and as root user (or with su) the fdisk command will be used to determine the hard disk partitioning.

fdisk -l

Often the boot disk is assigned to /dev/sda1, but requires checking.

The hard drive is mounted to a partition within the live CD. First create the partition and then mount it

mkdir /mnt/bootdisc
mount /dev/sda1 /mnt/bootdisk

This boot disk is now chrooted. This will enable the root of the system to be set within the temporary environment of the boot disk within which the root password command will be run.

chroot /mnt/bootdisk

And now we can run the password command to set the lost root password

passwd root

Having entered the password twice all can be tidied up.

First by unmounting the boot drive

umount /mnt/bootdrive

and by exit from root

exit

Finally remove the live CD and reboot.