Ubuntu locks the root account by default, but you can enable and change the root password when you need elevated privileges for system management.
This guide covers three methods to change the root password: the passwd command, the sudo passwd command, and the Settings GUI.
Quick Answer
Open Terminal and run sudo passwd root, then type your new password twice. This changes the Ubuntu root password without switching to the root account first.
Root account or sudo: which should you use?
Ubuntu ships with the root account locked on purpose. For almost all administration — installing packages, editing system files, restarting services — the recommended approach is to prefix a command with sudo rather than logging in as root. This keeps a clear audit trail and avoids leaving a full root session open.
Enable a root password only when a specific tool or recovery task genuinely requires an interactive root login. Server services do not need it either — software such as the LAMP stack on Ubuntu 24.04 runs under its own dedicated service accounts, and databases like PostgreSQL on Ubuntu 24.04 keep a separate postgres superuser rather than using the system root.
Method 1: Using the passwd Command
Step 1: Enable the Root User Account
Open Terminal with CTRL+Alt+T, then switch to the root user account with the command below. You will be prompted for your current user password.
sudo -i
Step 2: Change the Root User Password
Run the passwd command to open the password configuration utility. Type your new root password, then retype it to confirm the change.
passwd

Step 3: Log Out of the Root Account
Once the password is set successfully, run exit to log out of the root account and return to your standard user session.
exit
Step 4: Test the New Password
Verify the new password works by running su – and typing the new password when prompted. A successful login confirms the password was changed.
su -

Method 2: Using sudo passwd root
You can also change the root password from your normal user account using sudo. Run the command below, then type and retype the new root password.
sudo passwd root

Method 3: Using Settings (GUI)
Step 1: Open Settings
Press the Super key and search for Settings, then open it. This brings up the GNOME Settings panel where you can manage user accounts and passwords.

Step 2: Open Users
In Settings, navigate to System, then select Users to view all user accounts configured on your Ubuntu 24.04 system.

Step 3: Unlock User Settings
Click Unlock in the top right corner and enter your password to authenticate. This enables changes to password settings for any user account.


Step 4: Change the Password
Click the Password field for the account, enter the current password, type and confirm the new one, then click Change to apply.


How to Disable the Root Account
Once you are done, disable the root account to prevent unauthorized access. The command below removes the root password and locks the account.
sudo passwd -dl root
The -d flag deletes the password and -l locks the account, so no one can log in as root directly. Your normal user keeps administrative access through sudo, which is the state a fresh Ubuntu install ships in.
When to Change the Root Password
Change the root password when setting up a new Ubuntu server — often one you reach remotely after you install OpenSSH Server on Ubuntu 24.04 — after a security incident, or when rotating credentials on a regular schedule.
Use sudo passwd root for the quickest one-command reset from any terminal session. Use the Settings GUI if you need to change an account without opening a terminal.