How to Reset or Change the Root Password in Linux?

Learn via video courses
Topics Covered

Overview

The root account in Linux is the superuser account that has complete control over the system. It is crucial to keep the root password secure and known only to authorized individuals. However, there are cases where you may need to change or reset the root password.

In this comprehensive guide, we will explore different methods to reset and change the root password Linux provides us with:

  • Changing the root password as the root user
  • Changing or resetting the forgotten root password as a non-root user
  • Resetting the root password on boot

Introduction

The root user in Linux holds the highest level of administrative privileges and is essential for managing system resources and performing critical tasks. As a security best practice, it is crucial to periodically change the root password to prevent unauthorized access and protect the integrity of the system. Additionally, there may be instances where the root password is forgotten or needs to be reset due to various circumstances.

Whether you are a system administrator or a Linux user with root access, understanding how to manage the root password is essential for maintaining the stability and security of your system. So, let's dive into the various approaches for changing and resetting the root password in Linux.

Changing the Root Password as the Root User

Changing the root password as the root user is a straightforward process that can be done using the passwd command. Here are the steps to change the root password when logged in as the root user:

  1. Open a terminal or access the command-line interface:

    Start by opening a terminal window. You can do this by searching for "Terminal" in the applications menu or by using the keyboard shortcut (e.g., Ctrl+Alt+T).

    opening terminal

  2. Run the passwd command:

    In the terminal, type the following command and press Enter:

    running passwd command

  3. Enter the new root password:

    You will be prompted to enter the new root password. Type the new password and press Enter. Note that the password characters will not be displayed on the screen for security reasons.

    entering new passwd command

  4. Confirm the new root password:

    You will be asked to retype the new password for confirmation. Retype the new password exactly as before and press Enter.

    confirm new passwd command

  5. Password change successful:

    If the passwords match, you will receive a message indicating that the password has been successfully changed.

    password change successfully

It's suggested to choose a strong and secure password when changing the root password. A strong password usually includes a combination of uppercase and lowercase letters, numbers, and special characters. Avoid using common or easily guessable passwords.

Remember to keep the new root password secure and known only to authorized individuals. Regularly updating and changing passwords is good security practice and helps protect your Linux system from unauthorized access.

Changing or Resetting the Forgotten Root Password as a Non-Root User

Sometimes, you may forget the root password and find yourself unable to log in as the root user. In such cases, you can still change or reset the root password by following these steps as a non-root user:

  1. Open a terminal or access the command-line interface:

    Start by opening a terminal window. You can do this by searching for "Terminal" in the applications menu or by using the keyboard shortcut (e.g., Ctrl+Alt+T).

    opening of terminals

  2. Run the passwd command with sudo:

    In the terminal, type the following command and press Enter:

  3. Enter your current non-root password: You will be prompted to enter your current non-root password before you can change the root password. Type your current password and press Enter.

    enter your current non-root password

  4. Enter the new root password:

    Once you have provided your current non-root password, you will be prompted to enter the new root password. Type the new password and press Enter. Note that the password characters will not be displayed on the screen for security reasons.

    enter the new root password

  5. Retype the new root password for confirmation:

    To ensure there are no typos or mistakes, you will be asked to retype the new password. Type the new password exactly as before and press Enter.

    retype the new password for confirmation

  6. Password change successful: If the passwords match and the root password is successfully changed, you will receive a message indicating the update was successful.

    password change succesfully

After following these steps, you can now log in as the root user using the new password you set.

It is important to note that the ability to use the sudo command and change the root password as a non-root user is dependent on your system's configuration. Some systems may have restrictions or require additional permissions for non-root users to change the root password.

Always exercise caution and ensure that you have the necessary permissions and authorization to modify the root password. Changing the root password without proper authorization can compromise system security and may be a violation of policies or regulations.

Resetting the Root Password on the Boot

Resetting the root password on boot is a method that allows you to regain access to the root account when you have forgotten the password. This process involves modifying the boot parameters to boot into a single-user mode, where you can reset the root password. Here are the steps to reset the root password on boot:

  1. Reboot the Linux system:

    Start by rebooting the system. You can do this by clicking on the "Restart" option in the menu or by using the reboot command in the terminal.

    reboot the linux system

  2. Access the bootloader menu:

    During the boot process, you need to access the bootloader menu to act. This can usually be done by pressing a specific key, such as Esc, Shift, or F12, depending on your system. Consult your system documentation or try different keys until you see the bootloader menu.

  3. Edit the boot configuration:

    Once you are in the bootloader menu, use the arrow keys to select the Linux kernel you want to boot into. Then, press the "e" key to edit the boot configuration for that kernel. In this case, we are editing the configuration for Ubuntu.

    edit the boot configuration

  4. Open the Recovery Menu

    In the boot configuration, select the Recovery option for your system, in this case, we are using the Recovery menu for Ubuntu:

    open the recovery menu

  5. Select root

    Now, select the root option in the menu and press enter for getting the terminal to change the password

    select root

  6. Remount the root filesystem:

    Once you are in the root shell prompt, the root filesystem is initially mounted in read-only mode. To make changes, you need to remount it in read-write mode. Run the following command:

    remount the root filesystem

  7. Reset the root password:

    Now that the root filesystem is mounted in read-write mode, you can reset the root password. Use the passwd command followed by the username "root":

    You will be prompted to enter the new root password. Type the new password and press Enter. Retype the new password for confirmation.

    reset the root password

  8. Reboot the system:

    After changing the root password, you need to reboot the system to apply the changes accordingly. Use the following command:

    Alternatively, you can use the shutdown -r now command to initiate an immediate system reboot.

Once the system restarts, you can log in as the root user with the new password you set.

It's important to note that the steps mentioned above assume you have physical access to the Linux system and can reboot it using the physical access. These steps should be used responsibly and only on systems you have the authority to modify.

Conclusion

  • Changing the root password as the root user is a straightforward process that can be done easily using various techniques.
  • In this article, we learned how To reset or change the root password in Linux using various methods:
    • Changing the root Password as the root User
    • Changing or Resetting the Forgotten root password as a non-root user
    • Resetting the root password on boot
  • We also learned about user management techniques in Linux.