How to Enable and Disable Root User Account in Ubuntu

By 

Updated on

5 min read

Ubuntu Change Root Password

As a new Ubuntu user, you may wonder how to log in to your Ubuntu system as a root user or what is the default root password. In Ubuntu Linux, the root user account is disabled by default for security reasons.

This tutorial explains how to enable and disable the root user account in Ubuntu Linux.

Quick Reference

TaskCommand
Enable root accountsudo passwd root
Disable root accountsudo passwd -l root
Temporary root shellsudo -i
Switch to root (after enabling)su -
Run a single command as rootsudo some-command
Grant sudo access to a usersudo usermod -aG sudo username

Sudo Users

Ubuntu users are encouraged to perform system administrative tasks by granting administrative privileges to a regular user using a tool named sudo. Sudo allows authorized users to run programs as another user, usually the root user.

By default on Ubuntu systems, members of the group sudo are granted with sudo access. The initial user created by the Ubuntu installer is already a member of the sudo group. Chances are that the user you are logged in as is already granted with administrative privileges.

If you want to grant sudo access to another user, simply add the user to the sudo group:

Terminal
sudo usermod -aG sudo username

To temporarily elevate root user privileges, run the command prefixed with sudo:

Terminal
sudo some-command

The first time you use sudo in a session, you will be prompted to enter the user password.

If you want to run a command with sudo privileges without entering the password, you will need to edit the sudoers file. To do so type visudo:

Terminal
sudo visudo

This will open the /etc/sudoers file with your favorite command line text editor . Add the following line by replacing username with your username:

/etc/sudoerstxt
username ALL=(ALL) NOPASSWD: ALL

Accessing Root Without Enabling the Account

In most cases, you do not need to enable the root account at all. The sudo command provides several ways to get a full root shell temporarily.

To open an interactive root shell that simulates a full root login (with root’s environment and home directory), run:

Terminal
sudo -i

This is the recommended way to perform administrative tasks that require multiple commands as root. When you are done, type exit to return to your regular user session.

You can also use sudo su to switch to root. This combines sudo and su into a single command:

Terminal
sudo su

Another option is sudo -s, which opens a root shell but keeps your current user’s environment variables:

Terminal
sudo -s

All three approaches give you a root shell without permanently enabling the root account, which is the safer practice.

Enable Root User Account in Ubuntu

If for some reason, you need to enable the root account, you just need to set a password for the root user . In Ubuntu and other Linux distributions, you can set or change the password of a user account with the passwd command.

As a regular user in Ubuntu, you can only change your own password. The user you are logged in as must have sudo privileges to be able to set the root password.

To enable root account in Ubuntu, run the following command:

Terminal
sudo passwd root

You will be prompted to enter and confirm the new root password:

output
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Info
The password is not shown on the screen when you type it.

That is it. You have successfully enabled the root account. You can now log in to your Ubuntu machine as user root using the new password.

Once the root account is enabled, you can switch to it using the su command:

Terminal
su -

You will be prompted to enter the root password you just set. The - flag gives you a full login shell with root’s environment and home directory.

Disable Root User Account in Ubuntu

If you previously enabled the root user in Ubuntu and now you want to disable it, set the root password to expire.

To disable the root account password, use the following command:

Terminal
sudo passwd -l root

This locks the root account by prefixing the encrypted password with an exclamation mark, making it impossible to log in as root directly.

Troubleshooting

“Authentication failure” when running su - The root account does not have a password set by default in Ubuntu. You must first run sudo passwd root to set one before you can use su - to switch to root.

Account still locked after setting a password If you previously locked the root account with passwd -l, you need to unlock it with sudo passwd -u root or set a new password with sudo passwd root.

Cannot SSH as root Even with the root account enabled, SSH root login is disabled by default. The PermitRootLogin setting in /etc/ssh/sshd_config controls this. Enabling SSH root login is strongly discouraged for security reasons — use sudo over SSH instead.

FAQ

Why is the root account disabled by default in Ubuntu?
Ubuntu disables the root account as a security measure. Running commands directly as root increases the risk of accidental system damage. The sudo model provides the same capabilities while logging every privileged command and limiting exposure.

What is the difference between sudo -i and enabling root?
sudo -i gives you a temporary root shell that ends when you type exit. Enabling root creates a permanent account with its own password that anyone can log into. Using sudo -i is safer because it does not expose a persistent root login.

Is it safe to enable the root account?
It is generally not recommended. If you enable it, use a strong and unique password and disable it again when you no longer need it. For most tasks, sudo -i or sudo su are better alternatives.

Conclusion

To enable the root user account in Ubuntu, set a root password with sudo passwd root. To disable it, lock the account with sudo passwd -l root. In most cases, using sudo -i for a temporary root shell is the safer and recommended approach.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page