Site icon NetworkHunt

How to Change the Root Password in Debian?

change Root Password on Debian

Changing the root password on your Debian system is a fundamental administrative task for the security and management of your server. This post will help you change the root password on Debian using various methods.

Table of Contents
  1. What is a Root User in Debian?
  2. How to Change Root Password on Debian?
  3. Security Considerations

What is a Root User in Debian?

In Debian, the root user is the superuser account with unrestricted access to all system commands and files. By default, during the installation of Debian, if the root password is not set, then the root account is locked, and the initial user is granted administrative privileges through the sudo command. This setup enhances security by minimizing direct root access.


How to Change the Root Password on Debian:

Method 1: Changing the Root Password Using passwd

If you have access to a user account with sudo privileges, you can change the root password using the passwd command.

1. Open the Terminal or Connect via SSH:

After Logging in to the System, use the Keyboard Shortcut below to Open a Terminal Window:

Ctrl+Alt+T

To connect via SSH, use the command below:

$> ssh [username]@[System IP]

$> ssh network@10.10.1.54

Replace [username] and [System IP] with username of the User with Sudo Privileges, and IP Address of the System, respectively

2. Execute the passwd Command:

If you’re logged in as a user with sudo privileges, use:

$> sudo passwd root 

If you’re logged in as the root user, then use:

$> passwd
3. Set the New Password:

After running the passwd command you will be prompted to enter and confirm the new password for the root user. Ensure to choose a strong password that combines Uppercase and Lowercase Letters, Numbers, and Special Characters.


Method 2: Changing the Root Password Using su -

If you know the current root password, you can switch to the root user and change the password.

1. Open the Terminal or Connect via SSH:

After Logging in to the System, use the Keyboard Shortcut below to Open a Terminal Window:

Ctrl+Alt+T

To connect via SSH, use the command below:
$> ssh [username]@[System IP]

$> ssh network@10.10.1.54

Replace [username] and [System IP] with username of the User with Sudo Privileges, and IP Address of the System, respectivelyt via SSH: Log in to your Debian system.

2. Switch to the Root User:

Use the command below to Switch to Root user:

$> su -

You will be prompted to enter the current root password.

3. Change the Password:

Once switched to the root user, use the command below to change password:

$> passwd 

Then, enter and confirm the new root password as prompted.


Method 3: Resetting the Root Password in Single-User Mode

If you’ve forgotten the root password, you can reset it by booting into single-user mode.

1. Reboot the System:

Restart your Debian system, using:

$> sudo reboot
2. Access the GRUB Menu:

During boot, press and hold down the Shift key (If, a BIOS systems) or press ‘Esc’ (If, a UEFI systems) to access the GRUB menu.

3. Edit the GRUB Entry:
  1. Use arrow keys to highlight the Debian entry and press ‘E’ to edit.
  2. Find the line starting with Linux and append ‘init=/bin/bash‘ at the end of it.
4. Boot into Single-User Mode:

Press ‘Ctrl+X’ or ‘F10’ to boot the system. Now, the system will boot into Single-User Mode

5. Remount the Filesystem with Write Permissions:

Once the system boots, Use the command below to remount the root filesystem with read and write permissions:

$> mount -o remount,rw /
4. Reset the Root Password:

Now use the command below to reset the Root Password:

$> passwd

Enter and confirm the new root password as prompted.

5. Remount the filesystem with Read-only Permissions:

Use the command below to remount the filesystem with Read-only Permissions:

$> mount -o remount,ro / 

$> exec /sbin/init
6. Reboot the System:

Restart your Debian system, using:

$> sudo reboot

Security Considerations

Exit mobile version