How to Enable Root Account in Ubuntu Server (Step-by-Step Guide)

In this guide, we will look at how to enable the root account in Ubuntu Server. By default, the root account is disabled in Ubuntu Server for security reasons. Instead, Ubuntu uses sudo to perform administrative tasks. However, in some server environments, you may need to activate the root account.

Only on Ubuntu Server

Before we start, please note that this guide is only for Ubuntu Server. You should not enable the root account on Ubuntu Desktop; while it will work in the command line, the desktop environment is not designed to work with the root account.

Access the Root Account with Sudo

In a fresh installation, the root account is usually disabled. To begin, you must log into a user account that has sudo privileges.

After logging in, you can run the following command to switch to the root account:

sudo -i

When you press enter, it will ask for your own password. Once you authenticate, you will be switched to the root account. This is the standard way to access the root account with sudo.

How to Activate the Root Account

From here, if we want to activate the root account, what we need to do is set a password for the root account.

Use the following command to setup the root account password:

passwd

This step will set the root password and officially activate the account. You can now exit your current session and directly log into the root account using your new credentials.

Activate the Root Account on Ubuntu
Activate Root Account on Ubuntu

Enable Root SSH Login in Ubuntu Server (Optional)

If you need to enable root login via SSH, you must modify the SSH server configuration.

  1. Navigate to the SSH directory: cd /etc/ssh
  2. Edit the sshd_config file: The sshd_config file is the main configuration file for the SSH server. Open it using the Vim text editor: sudo vim sshd_config
  3. Modify PermitRootLogin: Find the line for PermitRootLogin.
  4. Remove the # to uncomment the line. If it says prohibit-password, change it to yes. This will allow root login by SSH.
  5. Save the sshd_config file.
  6. Restart SSH Server: For changes to take effect, restart the service using this command: sudo systemctl restart ssh
sshd_config file
Main configuration file for the SSH server
Enable Root SSH Login in Ubuntu Server
Enable Root SSH Login in Ubuntu Server

Now you can login as root in Ubuntu via SSH. Open a terminal and try to connect to your Ubuntu Server using the root account.

ssh to root account
ssh to root account

Final Thoughts

That is it for this guide on how to enable and activate the root account in Ubuntu Server. Remember, enabling root access can be risky, so use it only when required and always follow best security practices.