Set/Reset root Password and Enable Root Login in Ubuntu

Table of Contents

Introduction

The root user in Ubuntu is the user with administrative privileges, and it is recommended to use this account only when necessary. However, there may be situations where you need to reset the root password or enable root login in Ubuntu. In this tutorial, we will show you how to set/reset the root password and enable root login in Ubuntu.

Step 1: Boot into Recovery Mode

  1. Reboot your Ubuntu system.
  2. When the GRUB menu appears, use the arrow keys to select the “Advanced options for Ubuntu” option and press Enter.
  3. Select the recovery mode option and press Enter.

Step 2: Remount the File System in Read/Write Mode

Once you are in recovery mode, you need to remount the file system in read/write mode to be able to change the root password. To do this, follow these steps:

  1. Select the “root – Drop to root shell prompt” option and press Enter.
  2. Run the following command to remount the file system in read/write mode:
    mount -o remount,rw /

Step 3: Change the Root Password

Now that you have remounted the file system in read/write mode, you can change the root password. To do this, follow these steps:

  1. Run the following command to change the root password:
    passwd root
  2. Enter the new root password and confirm it.

Step 4: Enable Root Login

By default, the root account is disabled in Ubuntu, which means you cannot log in as root. However, you can enable root login by setting a password for the root account. To do this, follow these steps:

  1. Run the following command to set a password for the root account:
    sudo passwd root
  2. Enter the new root password and confirm it.
  3. Edit the following file:
    sudo nano /etc/ssh/sshd_config
  4. Find the line that says:
    #PermitRootLogin prohibit-password
  5. Uncomment the line and change it to:
    PermitRootLogin yes
  6. Save the file and exit the editor.
  7. Restart the ssh service:
    sudo service ssh restart

Conclusion

In this tutorial, we have shown you how to set/reset the root password and enable root login in Ubuntu. It is important to note that enabling root login can be a security risk, so it should only be done when necessary. Always use the root account with caution and only when it is absolutely necessary.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.