Enable root on ubuntu

Enabling the Root User in Ubuntu and Debian: A Comprehensive Guide


In the Linux world, the root user is the superuser with full administrative access to the system. This user can read, modify, and delete any file in the system, stop and start services, and even change the operating system’s settings. For security reasons, many Linux distributions, including Ubuntu and Debian, disable the root user by default. However, there are situations where you might need to enable the root user. This guide will walk you through the steps to safely enable and use the root user in Ubuntu and Debian.

Understanding the Root User

Before we delve into enabling the root user, it’s important to understand what the root user is and why it is typically disabled by default. The root user is like the ‘Administrator’ user on Windows – it has unrestricted access to the system. This section will explain the potential risks and benefits of enabling the root user.

How to Enable the Root User in Ubuntu and Debian

  1. Open a terminal session: This can typically be done by searching for ‘terminal’ in your operating system’s search bar or application menu.
  2. Get a root shell: Input the command sudo -i and press enter. This command stands for “substitute user do” and -i instructs the system to simulate a login shell. Essentially, you’re asking the system to treat you as the root user.
  3. Enter your password: You’ll be asked for your user password to confirm the action. Note that as you type your password, it won’t be displayed on the terminal, but the system is still registering your keystrokes.
  4. Set a password for the root user: Next, input the command passwd root and press enter. This will initiate the process to set a new password for the root user.
  5. Choose a strong password: You’ll be asked to enter a new password. Choose a strong, complex password to enhance your system’s security. Confirm this password by typing it again when prompted.

Now, the root user is enabled in your Ubuntu or Debian system. You can switch to the root user anytime by typing su - root in the terminal, followed by the root password when prompted.

This process is the same for most Debian-based distributions, including Ubuntu. However, it is generally recommended to use the root user sparingly due to its unlimited access to system files and settings. Instead, consider using the sudo command for performing administrative tasks.

Remember, while operating as the root user, it’s essential to be cautious as actions taken as root can significantly affect the system’s functioning and security.

Enabling Root Login via SSH

Allowing root login via SSH implies that if the password for the root account is compromised, an attacker would have full control over your system. It’s advised to use alternative methods, like logging in as a standard user and escalating privileges using sudo, instead of enabling root login via SSH.

However, if you need to enable it for some reason, follow the steps below:

  1. Open a Terminal Session: Same as before, search for ‘terminal’ in your system’s search bar or application menu.
  2. Open the SSH Configuration File: In the terminal, type the command sudo nano /etc/ssh/sshd_config and press enter. This command opens the SSH configuration file in the nano text editor. You might need to replace nano with vi or emacs or any other text editor you’re comfortable with.
  3. Find the Line that Reads ‘#PermitRootLogin’: In the text editor, look for the line that reads #PermitRootLogin prohibit-password or #PermitRootLogin no. This line might vary slightly based on your specific Linux distribution.
  4. Edit the Line: Remove the ‘#’ at the beginning of the line to uncomment it, and change the rest of the line to read PermitRootLogin yes. This change will allow the root user to login via SSH.
  5. Save and Exit the File: Press Ctrl+X to exit the file, then press Y when prompted to save the changes, and finally hit Enter to confirm.
  6. Restart the SSH Service: In the terminal, type the command sudo service ssh restart and press enter. This command will restart the SSH service and implement your changes.

You should now be able to log in as the root user via SSH. Remember, though, that this action presents a significant security risk and should be avoided if possible. It is much safer to log in as a regular user and use sudo to execute commands that require root access. If you absolutely must enable root login, be sure to use a strong, unique password for the root account to minimize the risk of unauthorized access.

Best Practices When Using the Root User

While having root access can be necessary for certain tasks, it is important to handle this power responsibly. Here are some best practices for using the root user safely:

  • Use sudo for Individual Commands: Instead of logging in as the root user, consider using the sudo command for individual tasks that require administrative privileges. This method provides an extra layer of security as it requires your password and limits the impact of a potential mistake or security breach.
  • Avoid Using the Root User for Daily Tasks: The root user should only be used for system administration tasks, not for everyday tasks like web browsing or checking emails. Using a regular user account for daily tasks reduces the risk of accidental system modifications and potential security breaches.
  • Logout of the Root Account When Done: Don’t stay logged in as the root user any longer than necessary. Once you’ve completed the tasks that required root access, be sure to log out of the root account. This minimizes the risk of inadvertently executing a command with root privileges.
  • Set a Strong Root Password: If you have to enable the root user, be sure to set a complex, unique password. This is your last line of defense if someone tries to gain unauthorized access to your root user account. Regularly changing your root password is also a good practice.
  • Disable Root SSH Login: As discussed earlier, allowing root login via SSH presents a significant security risk. It is generally recommended to disable root SSH login and use sudo instead for commands that require root privileges.
  • Keep the Root Account Disabled: Unless absolutely necessary, the root account should remain disabled. This adds an additional layer of security and limits the potential for unauthorized root access.
  • Regular Updates: Keep your system updated. Regular updates not only provide new features but also fix any known security vulnerabilities. Use the root user to install these updates to ensure that all system files get updated.
  • Backup Regularly: Always have a current backup of your important files. If something goes wrong while using the root user, having a backup allows you to restore your system to a functioning state without data loss.

Remember, with great power comes great responsibility. The root user is the most powerful user in a Linux system, and it should be used with caution. At PureVoltage, we’re dedicated to helping you manage your systems effectively and securely. For any assistance, don’t hesitate to contact us.

How to Disable the Root User in Ubuntu and Debian

  1. Open a Terminal Session: Just as before, search for ‘terminal’ in your system’s search bar or application menu and open it.
  2. Get a Root Shell: In the terminal, type sudo -i and press Enter. Enter your password when prompted.
  3. Lock the Root User Account: To disable the root user, type passwd -l root in the terminal and press Enter. This command will lock the root account, effectively disabling it. When the root account is locked, you will not be able to use it to log in or execute commands with root privileges.
  4. Exit the Root Shell: Finally, type exit and press Enter to leave the root shell and return to your normal user account.

Now, the root user is disabled in your Ubuntu or Debian system. You will still be able to perform administrative tasks using the sudo command from your normal user account, which is a safer practice than using the root account.

Remember, it’s crucial to maintain the principle of least privilege, which means giving users only the access they need to perform their tasks. Regularly using a root account for everyday tasks can expose your system to unnecessary risks.


In this comprehensive guide, we explored how to enable and disable the root user in Ubuntu and Debian. While the root user is a powerful tool, it also poses substantial security risks, so it’s important to understand when and how to use it safely.

We first explained what the root user is and why it is disabled by default in many Linux distributions. Then, we provided a detailed, step-by-step guide to enabling the root user, including how to set a password for the root account.

Next, we addressed the method to enable the root login via SSH, stressing the potential security risks associated with this action. Despite these risks, we explained how to make the necessary changes to the SSH configuration file to allow root login.

Finally, we provided instructions on how to disable the root user when it’s no longer necessary, a critical step to keep your system secure.

Remember, the root user has unrestricted access to the system, and therefore, its use should be minimized. Instead, consider using the sudo command to perform administrative tasks from your regular user account.

At PureVoltage, we understand the complexities and challenges of managing Linux systems. We offer a range of dedicated server and VPS services to help you optimize and secure your system. For any queries or further assistance, feel free to contact us. Our team of experts is always ready to help.