How To Change Root Password on Debian 12?
Changing the root password on Debian 12 is a security measure that can prevent unwanted access to the system by unauthorized users. The system grants the root user full access to all its functions and resources, such as installing or removing software, modifying system files, creating or deleting users, etc.
If someone gains access to your root account, they can compromise your system and data. So, it is recommended to change the default root password to a unique as well as strong one that is difficult to crack.
This guide will demonstrate all possible ways to change the root password on Debian 12. The supported content is given below:
Let’s start with the change of root password.
How To Change Root Password on Debian 12?
There are different methods to add/change root passwords, depending on how you access your system and what privileges you have. Here are some possible methods with detailed steps:
- Method 1: Using the passwd Command
- Method 2: Using the usermod Command
- Method 3: Using System Settings (GUI)
- Method 4: Using the Recovery Mode
- Bonus Tip: Using a live CD or USB
Method 1: Change Root Password on Debian 12 Using the passwd Command
This is the most common and straightforward way to change the root password. You need to have root access or sudo privileges to use this method. To change the root password, type:
sudo passwd root
It prompts users to type a new root password twice.
Alternative 1: Specify Root User
Another method is to use the su command with the -c option, which executes a command as the root user It prompts to enter current password, then the new password twice:
su -c 'passwd root'
Users can also use the passwd command with the -r option, which specifies the root user. Then, enter the new password twice:
sudo passwd -r root
Alternative 2: Switches to the Root User
Another method is to use the sudo command with the -i option, which switches to the root user. After that, use the passwd command without any option to change the root password. It prompts to enter only new root password as below:
sudo -i passwd
Method 2: Change Root Password on Debian 12 Using the usermod command
One of the ways to change the root password on a Linux system is to use the usermod command in a terminal. The usermod command can modify various attributes of a user account, such as the password, the home directory, the login shell, and more.
To change the root password using the usermod command, use the “usermod” command with the -p followed by the new password for the root account:
sudo usermod -p <newpassword> root
Specify Time for New Password
Alternatively, use the -e option to specify an expiration date for the new password. It forces the root user to change the password after a certain period of time:
sudo usermod -e 2021-12-31 -p <newpassword> root
It will set the new password to expire on December 31, 2024.
Method 3: Change Root Password on Debian 12 Using System Settings (GUI)
Another interesting way to change the root password on Debian 12 is via the graphical representation:
Step 1: Open System Settings
Click on the application menu icon from the taskbar at the bottom to navigate to system settings:
Step 2: Choose Users Options
Now, click on the “Users” option from the menu on the left screen. Next, click on “Password” field in the pop up interface:
Note: If this menu is locked, hit the “Unlock” button to confirm the authentication.
Step 3: Enter Password
Enter the current password and then input your desired new password twice for verification. Then, hit the “Change” button:
Important: Users must set the strong password when the security bar turns into green or yellow.
In this way, users have changed/configured the root password on Debian 12.
Method 4: Change Root Password on Debian 12 Using the Recovery Mode
This is a useful method if you forgot your root password and cannot log in to your system. After forgotten the root password of your Debian 12 system, users can reset it or change the root password by following these steps:
Step 1: Reboot System
First, reboot the system by pressing the Ctrl + Alt + Del and Now, press the “e” key on your keyboard to open the Grub Menu editing screen to edit the boot entry:
Step 2: Boot System into a Single-user Mode
Find the line that starts with linux and move to the end of that line and append the following text after “ro quiet:”. This will boot the system into a single-user mode with a bash shell. After that, press Ctrl+X to boot with the modified entry:
rw init=/bin/bash
Note: Users can also verify boot the system with the changes via Press F10..
Step 3: Check File System Permission
Once you get a root prompt, confirms the the root filesystem with read-write permissions by running below command:
mount | grep -w /
Note: If users need to remount the root file system in read-write mode type below command:
mount -n -o remount,rw /
Step 4: Change the Root Password
In this step, utilize the passwd command for changing the root password. It asks to enter the new password two times:
passwd
Step 5: Reboot the System
Finally, reboot the system by running the below script:
exec /sbin/init
Verification
You can verify that the password has been changed by logging out and logging in again as root with the new password:
In this way, the root password has been changed/modified on Debian 12.
Bonus Tip: Change Root Password on Debian 12 Using a live CD or USB
This is another method that can help you if you forgot your root password and cannot access your system. You need to have a live CD or USB of Debian or any other Linux distribution that can mount your file system.
To change the root password using a live CD or USB, follow these steps:
Step 1: Find Root Partition
Boot your system from the live CD or USB and open a terminal. You will need to find out the name of your root partition by typing the “fdisk” command:
sudo fdisk -l
Step 2: Mount Partition
Look for the partition that has / as the mount point and note its name (for example, /dev/sda1). Then, mount the partition by typing your actual partition name:
sudo mount /dev/sda1 /mnt
Next, chroot into the mounted partition by typing:
sudo chroot /mnt
Step 3: Set Root Password
Finally, you have root access to the original system. Now, use the “passwd” command to change the root password:
passwd
After that, type exit twice to leave the chroot environment. Then, reboot your system and remove the live CD or USB.
In this way, the root password is changed on Debian 12.
Conclusion
Changing the root password on Debian 12 is a simple and important task that you should do as soon as possible to secure your system. To change the root password on Debian 12, use the “sudo passwd root” command. It prompts users to enter a new root password and retype for verification. Alternatively, use the sysmod command or System Settings (GUI) or Recovery Mode or a live CD or USB.
The most recommended way to change the root password on Debian 12 is the “passwd” command. If users have forgotten their root password then Recovery Mode is the best option. If users are looking for the easiest way to configure/change root password, then go with the GUI method and set a new password for future use.

















