How to change the root password in Ubuntu 18.04, 20.04, 22.04, 24.04, 25.04, and 26.04
Read - 3 мин.
The article has been read - 83 раз
Updated - 19.06.2026
Published - 19.06.2026

How to change the root password in Ubuntu 18.04, 20.04, 22.04, 24.04, 25.04, and 26.04

The root user has full administrative privileges in the Ubuntu operating system. As root, you can manage users, network settings, packages, services, and all system files.

By default, the root account in Ubuntu is usually locked, and the sudo command is used to perform administrative actions. However, in some cases, administrators need to set or change the root password to perform special tasks.

These instructions are suitable for:

  • Ubuntu 18.04 LTS
  • Ubuntu 20.04 LTS
  • Ubuntu 22.04 LTS
  • Ubuntu 24.04 LTS
  • Ubuntu 25.04
  • Ubuntu 26.04 LTS

Checking Server Access

Connect to the server via SSH as a user with sudo privileges:

ssh username@server-ip

Example:

ssh admin@192.168.1.10

How to set a root password

If the root account doesn't already have a password, run:

sudo passwd root

The system will prompt you for a new password:

New password:
Retype new password:

After successful execution, a message will appear:

passwd: password updated successfully

After this, the root user will be able to use the set password to log in locally.


How to change the root password

To change an existing root password, you can also use the command:

sudo passwd root

Enter the new password twice to confirm the change.

After successful modification, the system will display:

passwd: password updated successfully

How to log in as root

After setting the password, you can switch to the root user:

su -

Enter the root password:

Password:

After successful authorization, the command prompt will change:

root@server:~#

How to temporarily gain root privileges without a root password

In most cases, setting a separate root password is not required. To run administrative commands, we recommend using:

sudo command

For example:

sudo apt update
sudo apt upgrade

To open a full root session:

sudo -i
or
sudo su -

This method is considered more secure and is recommended by Ubuntu developers.


How to disable the root password

If you no longer need to use root, you can disable the password:

sudo passwd -l root

After this, logging in as root using the password will no longer be possible.

To reactivate:

sudo passwd root

How to check the root account status

You can check the account status with the command:

sudo passwd -S root

Example output:

root P 2026-06-19 0 99999 7 -1

Where:

  • P — password set;
  • L — account locked.

Requirements for a secure root password

Since Root has complete control over the system, so the password must be as secure as possible.

Recommended:

  • at least 12-16 characters;
  • uppercase and lowercase letters;
  • numbers;
  • special characters;
  • a unique combination of characters.

Example:

Airnet#Root2026!Secure

Not recommended:

123456
root
password
admin123

Common Errors

Authentication Token Manipulation Error

This error is usually related to a lack of administrator rights or problems with the file system.

Check for sudo privileges:

sudo -l

Permission denied

This error occurs when attempting to change the root password without administrative privileges.

Use:

sudo passwd root

Security Recommendations

For internet-accessible servers, we recommend:

  • use SSH keys instead of passwords;
  • disable direct root login via SSH;
  • use sudo for administrative tasks;
  • enable two-factor authentication if necessary;
  • update your security system regularly.

Conclusion

You can change the root password in Ubuntu with one command:

sudo passwd root

However, for most servers, we recommend using sudo and don't enable persistent root login unless necessary.

Properly setting access rights can improve server security and reduce the risk of unauthorized access.


Order a VPS/VDS server with Ubuntu

All current versions of Ubuntu are available on AIRNET servers:

  • Ubuntu 18.04 LTS
  • Ubuntu 20.04 LTS
  • Ubuntu 22.04 LTS
  • Ubuntu 24.04 LTS
  • Ubuntu 25.04
  • Ubuntu 26.04 LTS

Choose the right plan and get full root access to your server:

Order a VPS/VDS server →

Answers to popular questions

How soon can I start using the service?

The user account is opened immediately upon application.

You can start using the service immediately after payment.

Author of the article:

user

Editor-in-Chief

Danaev Almaz