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:
Open Terminal on Ubuntu.
Type the following command to enable the root account and press Enter:
sudo passwd root
Create a password for the root account and press Enter.
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
Type the following command to open the Gnome configuration files with the text editor and press Enter:
sudo nano /etc/gdm3/custom.conf
Add the following line to enable root login under the “daemon” section:
Use the “Ctrl + O” and “Ctrl + X” to save and close the file.
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
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
The line should look like this:
#auth required pam_succeed_if.so user != root quiet_success
Type the following command to restart the system and press Enter:
Click the “Not listed?” option on the sign-in screen.
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.