how to enable root on ubuntu server

Ubuntu Server: How To Enable The Root User (Login & SSH)

For a long time, root was the default user on Linux, but it’s now disabled on most distributions. If like me, you were used to it, this article will answer your questions and guide you with the new best practice. I’ll also show you some workarounds if you really need “root”.

On Ubuntu Server, using “sudo” is the recommended method to get administrator privileges with the main user, instead of using “root”. If needed, the “root” user can still be enabled by setting up their password.

Let’s start with a bit of theory, to give you the context, and then I’ll show you how to enable root if you really want it, either in a terminal or even for SSH usage.

Linux doesn’t have to be intimidating. With my e-book, Master Linux Commands, you’ll uncover the secrets of the terminal in a fun, step-by-step journey. From basics to scripts, get ready to level up your Linux skills. Oh, and did I mention the handy cheat sheet you get as a bonus?

Is there a root user on Ubuntu Server?

The “root” still exists on Ubuntu Server and most Linux distributions, but can’t be used by default. The account is disabled for security reasons.

Why is the root user disabled on Ubuntu?

The root user was an easy target for hackers. It always has the same name (“root”) on any Linux distribution, and if the password was cracked, the hacker could get access to the entire system without limitations.

That’s why Debian, and most distributions based on it (like Ubuntu), decided to disable the superuser by default on new installations. Also, there are ways to get administrator privileges temporarily on these systems, so there is no real need to keep it enabled.

If you check the user list on your system, you’ll still find it, with the ID 0, but most likely can’t log in with it:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Sudo: a better way to run root commands

The sudo command is an abbreviation of “super user do”, and allows any user with enough permissions to run commands as if it was the superuser (root).

For example, if you try to update your system with:
apt update
It won’t work with your main user, administrator privileges are required.
But if, instead, you use:
sudo apt update
It should work if the current user has the permission to use sudo:

Sudo may ask for your password (the user password), to make sure it’s still you on the computer, but aside from that, it gives you the same privileges as root.

Join Our Community!

Connect, learn, and grow with other Raspberry Pi enthusiasts. Support RaspberryTips and enjoy an ad-free reading experience. Get exclusive monthly video tutorials and many other benefits.

Learn more

You can basically do everything with sudo, so, in theory, there is no need to use “root” anymore.

Related article: How To Use ‘sudo’: The Complete Linux Command Guide

Note: Not all users can use “sudo” by default, only the first user you created when installing your system. To give permission to another user, you need to add it to the “sudo” group, with:
sudo adduser <username> sudo
Doing this from an authorized user, obviously.

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

What is the root password on Ubuntu Server?

The root user is disabled by default, and so doesn’t have any password set. On old Ubuntu versions, it might be the one set during the installation, there is no default value.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

If you have access to a user account with the sudo permission, you can easily switch from the user to the root account with:
sudo su

If it asks for a password, type the one from the current user (“pat” in my example), and then you’ll be logged in as root:

Use the exit command to get back to your normal privileges.

I have explained that using “sudo” should be sufficient in most cases and that you can even temporarily switch to the root prompt in a terminal by using “sudo su”. You shouldn’t need anything more, but let’s discuss how to enable root if you really want to do this (not recommended).

Enable root login on Ubuntu Server

Before using the “root” account directly on Ubuntu Server, a password should be set via the command:
sudo passwd

It will first ask for the current user password (“pat” in my example), and then ask you to create a password for the superuser:

As explained previously, having root enabled on your system is a major security issue, so at least try to use a strong password for it. Length is key, using a password generator like this one can help you to get something long enough but easy to remember.

After setting up the password for the root user, you should be able to sign in with it directly when the system boots. But it won’t work for remote access, like with SSH, because there is an additional security measure to avoid this.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Enable root login over SSH

In addition to having the root user disabled by default on the Ubuntu server, connecting to it via SSH once enabled is also blocked.

Here is how to allow logging in as root via SSH:

  • Make sure the SSH server is installed:
    sudo apt install ssh
    You probably enabled it during the system installation, but it’s not mandatory, so take a few seconds to check that.
  • Edit the SSH server configuration file:
    sudo nano /etc/ssh/sshd_config
  • Find the line starting with “PermitRootLogin” in this file:

    As you can see, it’s forbidden to use it by default.
  • Uncomment this line, and switch the configuration to:
    PermitRootLogin yes
  • Save and exit (CTRL+X).
  • Restart the SSH service to apply the change:
    sudo service ssh restart

Once done, you should be able to use the root user directly from any computer on the same network:

Reminder: while enabling access to your system with the root user might be convenient, especially during the initial configuration of your system, it’s a huge security risk to keep it enabled all the time, and there is no real need to keep it enabled. Please try to use the “sudo” commands instead, and disable it as soon as possible.

You can revert the SSH configuration to block accesses with root, or completely disable the account with:
sudo passwd -l root

I also recommend reading and following my security tips for any Linux server here. I share the most important things you should do to keep your system safe. Working as a system administrator for almost 20 years, it was like my checklist for any new server installation.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.

Additional Resources

Overwhelmed with Linux commands?
My e-book, “Master Linux Commands”, is your essential guide to mastering the terminal. Get practical tips, real-world examples, and a bonus cheat sheet to keep by your side.
Grab your copy now.

VIP Community
If you just want to hang out with me and other Linux fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Python is a great language to get started with programming on any Linux computer.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.

Similar Posts