Sometimes remembering all the passwords, it's impossible, especially if you are a Linux Sys Admin who has to maintain a lot of servers. Loosing access to root, means loosing ability to do your job, managing servers, installing applications, updating etc.
However, If you have forgotten the password of your root account on Debian 12, don't worry about it because you can reset it, while there's no way to know what your old password was, there's a way to reset it.
In this tutorial we are going to show you how to reset the password of your root account on Debian 12.
Step 1 - Reboot your system
If you are stuck on the login screen of the computer that you can't get in, you can reboot it by pressing the power icon at the panel and then clicking to "Restart". If this doesn't work, you can manually do a force reboot/shutdown by pressing the power button on your computer.
Note:If your computer is already on, then simply reboot it. If it's off then there's no need to reboot after as we are rebooting only to get into GRUB menu.
Step 2 - Edit GRUB
Now, you need to enter in the grub file. To do this, you need to press the
e key once you see the grub screen as shown in the image below
Once you press the
e key, it should open grub in the edit mode
Note: Make sure to not edit anything else on the GRUB configuration file, as you may end up with a broken system, if you type something accidentally you can discard it by pressing the ESC button. Also, use only arrow keys to navigate on this file.
Now, you need to look for the line that starts with "linux", this line is that basically loads the kernel
Tip: Use the down arrow to go to the line that starts with "linux", then once you are in the linux line, use the right arrow to move to the end of line where it says "ro quiet"
Now, you need to delete
ro quiet at the end of the boot line, and replace it with the config below
And it should look like this
Now, save changes by pressing the F10 button or CTRL +X and it should boot Debian 12 with the option we added
What we are doing in this step, is that we are telling the system to boot up a shell session with read and write permission
rw so we can make changes to the system, in this case we need read and write permission to change the root password.
Step 3 - Change root password
To change the root password, first run the command below
root is the account that we're resetting the password for. You can also reset password for other accounts, to do this, simply replace
root with the account that you want to reset the password. For example, let's say that we want to reset password for account
owlhowto, then simply run
passwd owlhowto and enter the password.
Now on this step you need to enter the password two times as shown in the image below
Once root password has been successfully changed, you will see the output "passwd: password updated successfully" This means the new password is set, and you can use this password to login to your root account.
Step 4 - Boot the system with new password
Finally, you can boot the system and use the new password that you set. On the same shell session where you changed the password, run the command below to start the init process
Note: If the command above doesn't work, you can do a force reboot or shutdown by pressing the power button on your computer. Or if you are using virtualbox, you can just close the machine window and choose "Power off the machine".
And you should be able to login into your system using your root account .
In this tutorial, we explained how to reset the root password on Debian 12 by using the
rw init=/bin/bash option when booting Debian 12.