Handling multiple Linux systems or once in a while, there might be chances of forgetting the root user password. If so, here is the article to reset the root password on Debian 12 Linux (bookworm) servers or desktops.
Debian is quite popular among server users as compared to Desktop. And we all know how important is for a Server OS to be stable and maintained for the long term. That is the reason why we should give a chance to Debian Linux. It is already powering thousands of hosting and other servers around the globe.
However, what happens when you are not able to log in to your Debian server because you are in a situation where either you have forgotten or misplaced the root user account password? And without having the access to superuser you won’t be able to install most of the applications that required admin privileges.
Apart from that, losing access to the root account will also limit your access to perform system-critical tasks. Even modifying systems files and configuration will be limited. Well, I can understand the pain, and that’s why here in this article we will discuss the process of resetting the root password in Debian 12 Linux. So, that you can get back full control over your server or desktop.
In the resetting root password process, the user cannot recover the old password instead will be replaced or changed by the new one without knowing the old one.
A step-by-step guide to resetting the forgotten root password of Debian 12.
To reset the root password, first of all, we restart our Debian 12 system or virtual machine we are using. Soon as the system restarted, it will show you the Grub menu for a few seconds to select the advanced option. Press any arrow key to stop the system from further processing.
2. Modify GRUB to Reset the root password
To open the Grub Menu editing screen, press the ‘e‘ key on your keyboard. This will drop you on an editor, don’t touch or delete anything, just from here move to the next step.
3. Add rw init=/bin/bash to Debian 12’s Grub
You will see a couple of lines that tell the system how to boot itself, so don’t edit anything arbitrarily. Instead, use the arrow keys and move to the end of the line starting with “Linux“. At the end of this line after ro quiet type –
To have an idea you can see the given screenshot. Once you are confirmed that the added line is exactly, what we have shown here in the screenshot. After that boot your system with these added changes by pressing F10.
You might like to know what is “rw init=/bin/bash” is that we have added. It is a Linux boot option that tells the system to run the and drop us in a shell (“/bin/bash”) with read and write permissions (“rw” or read-write) to the file system. Whereas, the “init” in the command is the first process that runs when the operating system is booted, and it is responsible for starting and managing other processes.
4. Check file system permission
After following the previous step you will see yourself in the shell to execute the commands. Let’s first check whether we have read and write access to the Debian 12 file system or not. Because without that we cannot change the root password.
mount | grep -w /
The output must be with rw,realtime. It reflects that we have real-time- read-and-write access to the file system.
5. Reset the Debian 12 Root password
Finally, we will run the commands that will allow us to change the current forgotten root password of our Debian 12 Bookworm server or desktop system.
The command will ask you to type the password you want to set twice.
Well, if you want to change some other existing user account password apart from the root user then that can be done from here as well.
Simply type “passwd” command with the username. For example, if my non-root user account name is h2s, then to reset its password we will use:
7. Restart the system and login as root
Well, guys, we have successfully changed our current root Debian 12 Linux password without knowing the old one. Let’s now restart the system properly. For that execute the given command on your terminal.
Once the restart is done, you will see yourself on the Login screen of Debian 12 bookworm. Here you can use the root user and the password you have changed for it.
We cannot read or find the root password because it is saved in an encrypted format. The only way to recover your root user access is by resetting the password manually.
Those who have a user account with sudo access can switch to the root user without entering its password. For that, you have to use the command:
sudo su or
sudo su -
If you already have the access to sudo or root user then to change the password of the root you can run –
sudo passwd root