Ubuntu Linux

How to Enable root login in Ubuntu 18.04 (login as root)

Ubuntu does not enable the root account during installation and you will not be asked to create a root password. Instead, you will create a normal user account with sudo privileges. This user can run sudo command to perform administrative tasks.

We can enable Ubuntu root account by giving it a password by using the passwd command. But to run passwd command on the root account, you need to have sudo privileges.

Open the Ubuntu terminal and run the groups command to make sure that you are a member of the sudo admin group:

groups
run the groups command to make sure that you are a member of the sudo admin group

If you have sudo privileges, then you can set the root password with following command:

sudo passwd root

First, the command will prompt for your own password to confirm that you have sudo privileges.

After you’ve entered your password, the passwd command will prompts you to enter a new password for the root account (Twice).

the passwd command will prompts you to enter a new password for the root account.

Now you can log in to the root user  using the su – command and entering the root password when prompted.

su -

login as root in Ubuntu desktop GUI

If you want to login as root to the Ubuntu 18.04 desktop, you need to perform a couple of additional steps after enabling the root user:

Open /etc/gdm3/custom.conf and add AllowRoot=true under the [security] block:

[security]
AllowRoot=true

Next, open the /etc/pam.d/gdm-password and locate the following line:

auth	required	pam_succeed_if.so user != root quiet_success

And comment out the line (put # in front):

#auth	required	pam_succeed_if.so user != root quiet_success

After that restart your computer, when you come back to the login screen, click on the “not listed?”.

login as root in Ubuntu desktop GUI

Type the root in the username field and enter the root password.

error found when loading root

error found when loading root

To fix this error open the root profile in a text editor:

gedit /root/.profile

Find and Remove the following line:

mesg n || true

And replace it with following:

if `tty -s`; then
  mesg n
fi