It’s not uncommon for users to forget their root password. This happens especially when you stay for prolonged periods without using logging in or switching to root user. In case you have forgotten your root password, fret not. You can reset it in a few simple steps.
Let’s now see how you can reset a forgotten root password in Debian 10 or 11. For demonstration. We will use Debian 11.
Edit the GRUB menu settings
To get started, reboot your Debian system, and on the first boot entry as indicated below, press ‘e’ on the keyboard to access the GRUB editor.
You should be able to see a couple of lines on the editor like what we have here. Using your arrow down key, scroll down until you get to the line that begins with ‘linux’. Using the arrow forward key , navigate to the end of the line.
Be sure to delete the ‘ro quiet’ attributes.
Once deleted, enable access to the bash shell by typing init=/bin/bash
Next, press ctrl + x to boot into single-user mode.
Reset the password in single-user mode
Once you have accessed the single-user shell, mount the root filesystem with read and write access as follows:
# mount -o remount,rw /
Therefore, reset the root password by typing the command:
Enter your preferred root password and confirm. While at it, ensure that you provide a strong root password to avoid easily falling victim of bruteforce or dictionary attacks.
To effect the changes, exit the single-user mode and reboot by typing CTRL + ALT + DEL on the keyboard.
The fact that you can change the root user password implies that someone else who might have physical access to your PC or server can do the same and compromise your system. To prevent this, you can enable a BIOS password or alternatively, encrypt your filesystem with a password so that no one else can access the system without the password.
Great, you can now use the newly created password to log in or switch to your root user account. We hope that this guide was helpful in helping you reset your root password.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.