How to Change Root Password in Ubuntu Linux

Introduction

On all Linux and Unix-like systems, the root user (or superuser) is a special user account. It has complete and unrestricted access to all commands and resources on the system.

If you're switching from another Linux distribution to Ubuntu, you might be wondering what the default root password is and how to change it. The root user account is deactivated by default on Ubuntu for security concerns.

In this tutorial, we will show you how to switch to the root user account and set the root password on Ubuntu systems.

Temporary Switching to root

Granting sudo capabilities to regular users encourage Ubuntu users to do system administration duties. Authorized users can run programs as another account, usually, the root user, using sudo.

The sudo group is already a member of the account established by the Ubuntu installer. It's likely that the user you're now logged in as has administrative access.

Run the following command, prefixed with sudo, to temporarily boost root user privileges:

sudo command-name

You'll be prompted for the user password the first time you use sudo in a session.

You can use the sudo su or sudo -i commands and input the user password to temporarily switch to the root account in the current login session:

sudo su -

To ensure that the user has been changed, use the whoami command:

whoami
Output

root

Changing Root Password

Although the root user has been disabled, this does not imply that the root account has been deleted. Because the root account has no password, logging in as root is not feasible.

If you need to enable the root account for some reason, all you have to do is set a password for the root user. The passwd command on Ubuntu allows you to set or update a user account's password.

Run the following command as a sudo user to change the root user's password on Ubuntu:

sudo passwd root

The new root password will be required to be entered and confirmed.

Make sure you use a strong and unique password when creating the password. The most critical part of your account's security is having a strong password. A strong password often consists of at least 16 characters, one uppercase letter, one lowercase letter, one number, and one special character.

When you type the password, it does not appear on the screen.

Output

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

That's it. The password for the root account has been updated.

You can now use the new password to log in to your Ubuntu system as root.

FAQs to Change Root Password in Ubuntu Linux

Can I change the root password without knowing the current one? 

No, you need to know the current root password to change it. If you have forgotten it, you can reset it using the recovery mode on Ubuntu.

Is it recommended changing the root password on Ubuntu? 

Yes, it is generally advised to change the default root password to enhance system security.

Are there any restrictions on the length or complexity of the root password? 

There are no specific limitations on the length or complexity of the root password. However, it is recommended to choose a strong and unique password for better security.

Does changing the root password affect other user accounts? 

Changing the root password only affects the root account. It does not modify any other user accounts on the system.

Can I disable the root account after changing the password? 

Yes, it is possible to disable the root account by using the command sudo passwd -l root. This prevents anyone from logging in as root directly.

I cannot set a new root password, what should I do? 

If you are experiencing difficulties setting a new root password, make sure you have appropriate permissions and consult Ubuntu's documentation or seek support from the community.

Is it possible to reset the root password if it is forgotten? 

Yes, you can reset the root password if it is forgotten by booting into the recovery mode of Ubuntu. This allows you to access the root account and set a new password.

Conclusion

The root account on Ubuntu has no password by default. To run commands with root capabilities, the sudo command is advised.

You'll need to set the root password before you can log in as root.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.