How To Reset Root Password on Debian 11 | Easy Steps

Posted on

How To Reset Root Password on Debian 11 | Easy Steps

How To Reset Root Password on Debian 11 | Easy Steps

This guide intends to teach you How To Reset Root Password on Debian 11. In Linux, regular users and superusers are allowed to access services via password authentication. In the case that a regular user can’t remember his/her password, a superuser can reset the password of a regular user right from the terminal.

However, what if the superuser (or root user) loses his/her password? They will have to recover the lost password before booting into the login screen. This allows any malicious user with physical access to your Linux host to gain complete ownership. This article on the Orcacore website takes a look at how to recover a lost root password on Debian 11.

In this guide, we will show you how to reset the Lost Root Password from the Grub Menu on Debian 11. Follow the steps below to complete this guide.

First, you need to restart your system, and while doing that, press and hold the Shift key on your Keyboard. This will drop you into the Grub menu of Debian 11.

Next, you need to press the ‘e’ key on your keyboard. This will let you edit the Grub’s boot prompt. Don’t touch or delete anything here. Once you have the editor, move to the next step.

At this point, use your arrow key and move to the end of the line starting with “Linux”. There at the end of this line type rw init=/bin/bash.

rw init=/bin/bash
Grub Menu

After adding the syntax, boot your system with this configuration. To do this, you can use Ctrl+X or F10.

2. Root Shell Access on Debian 11

At this point, without providing any password, you will have Debian 11’s shell with root access. First, let’s check whether your user has read and write access to the file system where the OS has been installed.

To do this, run the following command:

mount | grep -w /

If you see (rw,realtime) in your output, it means you have real-time read and write access to the file system.

3. Change Root Password on Debian 11

Now you can simply change your root password on Debian 11 with the following command:

passwd

The system will prompt you to add a new password two times.

To change the password of a user other than root, we have to mention the username of the same. The syntax is like the following command:

passwd username

When you are done resetting your Linux password, restart your system to log in with the changed password. For rebooting, run the command below:

exec /sbin/init

After that, hit the Enter key.

From here, you can log in and access your system with the newly set root password.

Conclusion

Resetting the root password on Debian 11 involves booting into recovery or single-user mode, accessing the root shell, and using the passwd command. This process is straightforward but should be done with caution to maintain system security.

Hope you enjoy it. You may be interested in these articles:

Install and Use Visual Studio Code on Debian 11

Set up and Configure Fail2ban on Debian 11

How To Install LEMP stack on Debian 11

Alternative Methods to Reset Root Password on Debian 11

While the method described above, which leverages the GRUB menu, is a common and effective way to reset a forgotten root password on Debian 11, there are alternative approaches that can be employed. These methods might be more suitable depending on your specific situation and technical comfort level. Below are two alternative ways of How To Reset Root Password on Debian 11.

Method 1: Using Recovery Mode

Recovery mode provides a minimal environment where you can perform administrative tasks, including resetting the root password. This method is especially useful if you’re having trouble editing the GRUB menu directly.

  1. Boot into Recovery Mode: Restart your Debian 11 system. During the boot process, you may need to press a key (like Esc, F2, or F12 – consult your motherboard documentation) to access the boot menu. From the boot menu, select "Advanced options for Debian GNU/Linux". You should then see a list of kernels. Choose the kernel with "(recovery mode)" appended to it and press Enter.

  2. Navigate to Root Shell: After the system boots into recovery mode, you’ll be presented with a menu. Choose the "root Drop to root shell prompt" option. This will give you a root shell without requiring a password. If you don’t see this option immediately, you might need to select "Network" first to enable networking (if needed) and then return to the main menu.

  3. Mount the Root Filesystem: The root filesystem might be mounted as read-only. Remount it with read-write permissions using the following command:

    mount -o remount,rw /
  4. Change the Root Password: Now, use the passwd command to change the root password:

    passwd

    Enter the new password when prompted and confirm it.

  5. Reboot the System: After successfully changing the password, reboot your system:

    reboot

    You should now be able to log in as root with the new password.

Method 2: Using a Live CD/USB

If you have access to a Debian Live CD or USB drive, you can use it to boot your system and then access and modify the root password. This method is useful if you’re unable to access the GRUB menu or recovery mode.

  1. Boot from Live Media: Insert the Debian Live CD/USB into your system and boot from it. You may need to change the boot order in your BIOS settings to prioritize the CD/USB drive.

  2. Identify the Root Partition: Once the live system has booted, you need to identify the partition where your Debian 11 installation resides. You can use the lsblk command to list the block devices and their partitions:

    lsblk

    Look for the partition that contains your root filesystem (usually labeled with a mount point of /). It’s important to identify the correct partition to avoid data loss.

  3. Mount the Root Partition: Create a mount point and mount the root partition:

    mkdir /mnt/debian
    mount /dev/sdaX /mnt/debian  # Replace /dev/sdaX with the correct partition

    For example, if your root partition is /dev/sda2, the command would be mount /dev/sda2 /mnt/debian.

  4. Chroot into the Mounted Partition: Use the chroot command to change the root directory to the mounted partition:

    chroot /mnt/debian

    This effectively places you inside your Debian 11 installation’s filesystem.

  5. Change the Root Password: Now you can change the root password using the passwd command:

    passwd

    Enter the new password when prompted and confirm it.

  6. Exit Chroot and Unmount: Exit the chroot environment and unmount the partition:

    exit
    umount /mnt/debian
  7. Reboot the System: Reboot your system and remove the live media. You should now be able to log in as root with the new password.

These alternative methods provide flexibility in recovering a forgotten root password on Debian 11, ensuring you can regain access to your system even in challenging situations. Remember to exercise caution and double-check your commands to avoid unintended consequences. Learning How To Reset Root Password on Debian 11 is important.

Leave a Reply

Your email address will not be published. Required fields are marked *