How to Change Root Password in Ubuntu Linux

By 

Updated on

4 min read

Ubuntu Change Root Password

The root user (or superuser) is a special user account that is present on all Linux and Unix-like systems. It has full access to every command and any resource on the system without any restrictions.

If you are coming to Ubuntu from another Linux distribution, you may wonder what the default root password is or how to change the root password. By default, in Ubuntu, the root user account is disabled for security reasons.

This tutorial explains how to temporarily switch to the root user account and how to set the root password on Ubuntu systems.

Temporary Switching to root

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

The initial user created by the Ubuntu installer is already a member of the sudo group. The chances are that the user you are logged in as is already granted with administrative privileges.

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

Terminal
sudo command-name

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

To temporarily switch to the root account in the current login session, you can use either the sudo su or sudo -i command and enter the user password:

Terminal
sudo su -

Run the whoami command to verify that the user is changed:

Terminal
whoami
output
root

Changing Root Password

The root account still exists, but its password is locked by default. This prevents password-based root login until you set a password for the account.

If for some reason, you need to enable the root account , all you need to do is to set a password for the root user. In Ubuntu, you can set or change the password of a user account with the passwd command.

To change the password of the root user in Ubuntu, run the following command as a sudo user :

Terminal
sudo passwd root

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

When setting the password, make sure you are using a unique and strong password. Having a strong password is the most important aspect of the security of your account. Often a strong password has at least 16 characters, at least one uppercase letter, one lowercase letter, one number, and one special character.

The password is not shown on the screen when you type it.

output
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

The root password has now been changed.

You can now switch to root with su - or use the password for a local root login where direct login is allowed. This does not enable SSH password login for root, which is controlled separately by the SSH server configuration. When you no longer need password-based root access, you can lock the root password again.

FAQ

What is the default root password in Ubuntu?
There is no usable default root password. Ubuntu ships with the root password locked, and sudo passwd root replaces the locked value with the password you set.

How do I log in as root in Ubuntu?
The recommended method is to open a root shell with sudo -i or run individual commands with sudo. To switch users with su -, first set a root password with sudo passwd root. SSH root login is controlled separately by the SSH server configuration.

How do I disable the root password again?
Lock the password with sudo passwd -l root. This disables password-based root login, but it does not disable the account or block other authentication methods such as SSH keys. See enabling and disabling the root user account for details.

Conclusion

By default, Ubuntu keeps the root password locked. The recommended approach is to use the sudo command to run commands with root-level privileges.

To be able to log in as root directly, you will need to set the root password with sudo passwd root. If you only need root privileges for occasional tasks, stick with sudo and leave the account locked.

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