How to Log In as Root on Ubuntu

Want to use superuser privileges on your Ubuntu PC? You’ll need to login as root on Ubuntu using this guide.

If you’re a new Linux user, you might be unfamiliar with some of the differences it has, especially compared to a Windows PC. On Windows, most users are administrators, allowing you to install new apps and make changes to system hardware. On a Linux distro like Ubuntu, the root user is in control, but it isn’t best practice to log in as root directly (although you can if you need to). Instead, you can log in as root on Ubuntu using these steps.

Can I Use the Root User as My Normal User Account on Ubuntu?

In Ubuntu, the root user account gives you full and complete permission to modify system files and settings. Most Linux distributions, including Ubuntu, advise against using the root account for daily operations.

The reason is simple: you have unlimited power to control your system. If you chose to do so, you could completely wipe your PC’s files with a single command. The root account is powerful but also risky, and by design, Linux tries to avoid putting you in a situation where you could cause that damage.

Ubuntu disables the root user by default. This is to encourage the use of a regular user account with sudo privileges. Sudo allows you to run commands with administrative permissions without staying logged in as root.

Having a separate user account that can be temporarily elevated to use root-level admin power enhances your Linux system’s security. It acts as a safety buffer to prevent accidental (or potentially malicious) changes that could harm your system.

While you can use the root user account, it’s safer to stick to your regular account and invoke root privileges only when necessary.

How to Log In as Root in Ubuntu Using su or sudo

Gaining root access in Ubuntu is a controlled process, but you can do so using the sudo and su commands. These commands allow you to execute commands with the necessary superuser privileges.

Using su

The su (substitute user) command is straightforward but less commonly used for root access in Ubuntu because the root account is typically locked without a password set. It switches the current user to another user, root in this case, but only if you have the proper credentials.

  1. You’ll need to change the root password first, so you’ll need initial access to sudo. Open a new terminal window (Ctrl + Alt + T on your keyboard), type sudo passwd root, press Enter, and set a secure password.
    Set new root password in Ubuntu
  2. Once the root password is set, you can switch to the root user using su - and enter the root password you’ve just created.
    Running the su command in Ubuntu
  3. The terminal you’re using is now signed in as root—you can now execute commands.

Using sudo

The sudo command is a safer alternative that limits root-level access to those users included in the sudoers file. It’s more secure because it requires the user’s password, not the root password, and leaves the main root account locked.

  1. To log in as root using sudo, press Ctrl + Alt + T on your keyboard to open a new terminal window.
  2. In the terminal, type sudo -i to start a root shell session.
  3. If prompted, enter your user password.
    Run sudo -i in Ubuntu

The terminal prompt will change from $ to # to indicate that you’ve gained root access. Using sudo is generally considered the better option over su due to the enhanced security it provides.

How to Run Applications as a Root User in Ubuntu

In Linux, you’ll need to execute (or run) a script or application as the root user (or with root-level access) in certain situations. For instance, if you’re trying to make changes to your system, such as upgrading an application, you’ll need root access to do it.

You’ll typically use the sudo command to run programs as root on an Ubuntu PC. To execute commands as root in the terminal, follow these steps.

  1. Open a new terminal window.
  2. Type the sudo command followed by the desired command (eg. sudo ls).
  3. Enter your password, if prompted—it won’t appear on the screen for security reasons.
  4. Press Enter to execute the command.
    Example use of the sudo command in Ubuntu

How to Disable Root Access on Ubuntu

If you’ve previously enabled root access on your Ubuntu by enabling the root account, you can disable it using the sudo passwd command. To disable root access on Ubuntu, follow these steps.

  1. Open a new terminal window.
  2. Type the command sudo passwd -l root and press Enter.
  3. If prompted, type in your root password.
    Locking the root account in Ubuntu

This command locks the root account and ensures that no user can log in using it. The -l flag stands for lock, removing the root password and preventing you (and others) from signing into it.

However, this won’t stop all root-level access to your PC. You can still use sudo to elevate your commands to use root-level access—as long as your user account has the necessary privileges.

Managing Your Ubuntu PC Using Root

I don’t tend to sign in directly as the root user on my Ubuntu installation, and in most cases, you shouldn’t need to, either. Stick to using sudo to access the admin privileges you need, but if you need to, you can use sudo su - to log in as the root user directly.

Remember to take great care as the root user, however. You’ll have the power to wipe your complete installation if you want to—use it wisely!

To Top