How to enable login as root on Ubuntu

Do you need root access on the desktop environment of Ubuntu? If so, here's what you need to do.

Ubuntu enable root login

On Ubuntu, you can access the desktop as the “root” user, but you need to enable the account manually, and in this guide, you will learn how. When installing Ubuntu with the graphical user interface (GUI), the setup disables the root account by default, meaning that you must use the “sudo” command and provide your local account password to run a command with root privileges.

Although this is the recommended approach to using the operating system to prevent unwanted changes and improve security, you may still find some situations when logging in a root may be beneficial. For instance, when you need to set up and test an application that you will later deploy on a server, and you don’t want to install the server version without a desktop since using the GUI makes it easier to work back and forth between the guest operating system and the virtual machine. Or you’re comfortable using the root account and want unrestricted access to the device.

Whatever the reason might be, on Ubuntu (if you use the GNOME desktop), you can configure the system to enable the root account and make it available through the sign-in screen.

This guide will teach you the steps to log in as root on your Ubuntu server configured with the desktop environment.

Enable desktop root access on Ubuntu

To enable access to the Ubuntu desktop with the root user, follow these steps:

  1. Open Terminal on Ubuntu.

  2. Type the following command to enable the root account and press Enter:

    sudo passwd root

    Enable root account

  3. Create a password for the root account and press Enter.

  4. Type the following command to create a backup of the configuration file and press Enter:

    cp /etc/gdm3/custom.conf /etc/gdm3/custom.conf.bak
  5. Type the following command to open the Gnome configuration files with the text editor and press Enter:

    sudo nano /etc/gdm3/custom.conf
  6. Add the following line to enable root login under the “daemon” section:

    AllowRoot=true

    Allow root login at sign-in screen

  7. Use the “Ctrl + O” and “Ctrl + X” to save and close the file.

  8. Type the following command to open the gdm-password file to configure the PAM authentication daemon file and press Enter:

    sudo nano /etc/pam.d/gdm-password
  9. Type “#” at the beginning of the following line to prevent the system from blocking access to the root desktop access:

    auth required pam_succeed_if.so user != root quiet_success

    Ubuntu root settings

    The line should look like this:

    #auth required pam_succeed_if.so user != root quiet_success
  10. Type the following command to restart the system and press Enter:

    reboot
  11. Click the “Not listed?” option on the sign-in screen.

  12. Confirm the “root” username and password, and press Enter.

Once you complete the steps, you will log in as the “root” user, giving you unrestricted access to the Ubuntu system.