Debian: I've lost my root password, what can I do?
What's in the box?
You've lost the root password for your Debian machine and you don't know what to do? You'd like to reset the root password, but how? Don't panic, we'll show you how in this article! The good news is that there's a method for this.
Access to administrative tasks on a Linux machine relies on the "root" account, or the use of "sudo" with an account that has the appropriate permissions. However, it is essential to have access to the root account itself. In this example, I'm using a machine running Debian 11 Bullseye, but the same applies to other versions and systems.
Here are the steps to reset the root password on Debian 11The system is based on the assumption that it is lost. Take care by following the steps below.
1. Access the Grub menu
Grub is the startup program of a Linux machine: it is displayed when the machine boots. To reset the password, we need to access the Grub menu on our Debian 11 Bullseye machine. To do this, reboot your system and, while you're at it, press the Shift key on your keyboard to access Debian 11's Grub menu.
In the vast majority of cases, the Grub is displayed when the machine starts up, so simply press the down arrow (for example) to stop the countdown and stay on the Grub menu.
2. Edit Grub menu
The next step is to change the default boot entry for your Debian 11. To do this, follow these steps, press the "e" key on your keyboard to edit the contents of the Grub menu. For the time being, don't modify the content, and don't delete lines either. Once you have access to the editor, proceed to the next step.
On the Grub editing screen, use the arrow keys on your keyboard to move to the end of the line beginning with "Linux. There, at the end of this line, write this after :
rw init=/bin/bash
Thanks to this modification, you'll have access to the Linux shell without providing a password, all with the root account! This will be very useful for resetting the root account password.
Press "CTRL + X" to apply the configuration and restart the machine.
Here's an example to guide you:
3. Test shell access as root
First, let's check whether our user has read and write access to the file system where the operating system is installed.
To do this, use a :
mount | grep -w /
If the command returns a line with the value "(rw,realtime)" at the end, this means you have read and write access to the file system. This means it will be possible to change the password, as you have write rights.
4. Reset root password
Now let's change the password as we normally do on a Linux system using the following command:
passwd
To change the password of a user other than root, we need to specify the user name. For example, if the user ID is "tutobox", we'll do :
passwd tutobox
5. Restart the system
Once you've reset your Linux root password, reboot your system to log in with the new password! To reboot, type :
exec /sbin/init
From here, you can log in and access your system with the new root password.
Thanks to this new article in the IT tutorial box, you will be able to reset root password on a Linux machine in case you've lost it, or don't know it!
Resources :
Thank you very much for this practical guide!
Hello
"I've lost the ROOT password, what can I do?"
My distribution is Linux Mint19 "Tara" Cinnamon Edition
GNU GRUB version 2.06
I got as far as step 4. Reset root password. After validating the passwd command, the cursor flashed, without letting me enter a (new) password.
Thank you in advance and best regards
Alain Hoffmann
02 VIII 2023
Very useful,
Well thank you for these orders that save the situation.
It doesn't work, as always with tutorials posted on the internet ... type everything correctly, press CTRL+X and when it restarts, it keeps asking me for the damn password....
You wrote: "just press the down arrow to stop the countdown" then you wrote "press the e key".
That's how you screw up a tutorial.
For this to work, you need to press the e key if Grub is pointing to the first line.
Not the recover line!
My linux is two years old
Works very well with Pepper Mint (Debian) 6.1.0.23-amd64, an old laptop.