How to Change Root Password in Ubuntu 24.04

The root password is one of the core security layers of an operating system like Ubuntu. A root user has the highest level of privileges, if it gets hacked, all of your personal data will be at risk. Therefore, it is recommended to change the root password regularly. This exercise reduces the possibilities of cyberattacks and enhances the security of your system. 

In this Linux tutorial, we’ll show you several methods of changing the root password in Ubuntu 24.04.

How to Change/Reset Root Password in Ubuntu 24.04

We can change the root password in Ubuntu 24.04 by logging in as a root user, a regular user with sudo privileges, or by entering into recovery mode.

Method 1: Changing Root Password as a Root User

The root is a superuser account used to manage administrative tasks in Linux and Unix systems. It has the highest level of privileges that allows us to perform any action on the system, including resetting the root password. Here is how you can change the root password as a root user in Ubuntu 24.04:  

Step1: Switch to the Root Account

First, execute one of the following commands to log in as a root user:

sudo su -sudo isudo su
Change Root Password In Ubuntu 24.04 A

Step 2: Verify the Root User

We can use the whoami command to ensure that we are logged in as a root user:

whoami
Change Root Password In Ubuntu 24.04 B

Step 3: Change Root Password

Now execute the passwd command to update the root password:

passwd
Change Root Password In Ubuntu 24.04 C

Step 4: Exit From Root User

Once the root password is updated, it is recommended to exit from the root user. To do this, simply type exit in the terminal:

exit
Change Root Password In Ubuntu 24.04 D

Method 2: Changing Root Password as a Regular User

A normal user with sudo privileges can also update the root password in Ubuntu 24.04. To do this simply execute the “passwd” command with the sudo privileges, as follows:

sudo passwd root
Change Root Password In Ubuntu 24.04 E

Important Consideration: We can use this command with the following syntax to change the password of any user:

sudo passwd <username>

Method 3: Changing Root Password From GRUB Menu | Recovery Mode

We can also access the GRUB menu and update the filesystem according to our requirements. For instance, we can boot into recovery mode, drop into the root shell prompt, and execute the passwd command to change the root password using the GRUB menu. Here is step by step demonstration of this method:

Step 1: Boot Into Recovery Mode

While a virtual machine is booting, press and hold the “ESC” key from your keyboard to enter the GRUB menu. From there, select the “Advanced options for Ubuntu” using the arrow keys and hit the Enter key to proceed:

Change Root Password In Ubuntu 24.04 F

Now select the highlighted option and press Enter to boot the system into “recovery mode”:

Change Root Password In Ubuntu 24.04 G

Step 2: Drop to Root Shell Prompt

From the recovery menu, select the “Drop to Root Shell Prompt” option and press Enter:

Change Root Password In Ubuntu 24.04 H

Upon pressing the Enter key, the system will ask you to provide the root password for maintenance:

Change Root Password In Ubuntu 24.04 I

Specify the current root password and press Enter to log in as a root user.

Step 3: Update the Root Password

After password authentication, execute the given command to set a new root password:

passwd
Change Root Password In Ubuntu 24.04 J

How to Change/Reset the Forgotten Root Password in Ubuntu 24.04

If for some reason the root password is lost, you can recover it by using the Recovery Mode or by editing the Filesystem commands.

Method 1: Resetting the Forgotten Root Password Using Recovery Mode

You can easily reset the forgotten root password from the recovery mode. For this purpose, simply go through the following steps:

  • Boot Into Recovery Mode (Same as the step 1 of method 3)
  • Drop to Root Shell Prompt (Same as step 2 of method 3)
  • Remount the Root with Write Permissions
  • Reset the Root Password
  • Remount the Root with Write Permissions

After entering into the root shell prompt, execute the following command to remount the root filesystem with read and write permissions:

mount -rw -o remount /

Here, “-rw” indicates the read-write permissions for the root filesystem while the remount option is used to remount the root filesystem “/”:

Change Root Password In Ubuntu 24.04 K
  • Reset the Root Password

Now you can execute the passwd command to easily reset your forgotten root password:

passwd root
Change Root Password In Ubuntu 24.04 L

After this, execute the “exit” command to exit from the root shell prompt and navigate back to the recovery menu. Select the “Resume Normal Boot” option, and you will be able to log in with the new root password.

Method 2: Resetting the Forgotten Root Password by Editing the Boot Commands

Alternatively, you can enter the GRUB Menu and edit the boot commands to mount your filesystem with the write permissions. Once done, you can execute the passwd command to reset the forgotten root passwd. Here are the steps required to reset the forgotten password on Ubuntu 24.04:

  • Edit the Boot Commands
  • Mount the Filesystem With Write Permissions
  • Reset the Root Password
  • Edit the Boot Commands

Enter the GRUB Menu, select the boot entry that you want to update using the arrow keys, and press “e” to edit the commands for system login:

Change Root Password In Ubuntu 24.04 M
  • Mount the Filesystem With Write Permissions

Now locate a file starting with “Linux”, currently our filesystem is mounted with “ro” permissions (read-only):

Change Root Password In Ubuntu 24.04 N

Change read-only to read and write permissions. Also, append the “init=/bin/bash” at the end of this line to get direct access to a shell prompt with root privileges:

Change Root Password In Ubuntu 24.04 O

Press “CTRL + X” from your keyboard to reboot the system with the updated settings.

  • Reset the Root Password

Now execute the passwd command to reset your root password:

passwd
Change Root Password In Ubuntu 24.04 P
  • Reboot the System

Once the root password is successfully updated, execute the given command to reboot the system (the standard reboot command might not work in this case):

exec /sbin/init

Now you can access your root account with the updated password.

How to Fix “passwd: Authentication token manipulation” Error in Ubuntu 24.04

While changing/updating the root password, you may encounter an error stating “passwd: Authentication token manipulation”. This error occurs because our filesystem is, by default, mounted with read-only permissions; hence, we can’t update the password. To resolve this, we must provide the read-write privileges to the filesystem. For this purpose, we must execute the following command before changing the root password:

mount -rw -o remount /

How to Change/Reset Sudo Password in Ubuntu 24.04

In Linux distributions, like Ubuntu, the sudo password is required to perform administrative tasks using the sudo command. Sudo password grants administrative permissions (temporarily) to a user without logging in directly as a root user. Changing the sudo password regularly reduces the chances of cyber attacks. We can easily change the sudo password using a terminal or graphical interface.

Method 1: Changing Sudo Password Using CLI

We can change the sudo password by executing the “passwd” command with the sudo privileges from the terminal. To execute this command, follow the mentioned syntax:

sudo passwd <username>

Method 2: Changing Sudo Password Using GUI

Users that are new to Ubuntu or less familiar with the command line interfaces, can opt for the GUI method to change the sudo password. Here is how this method works in Ubuntu 24.04:

Step 1: Open the User Settings

Open settings, select “System” from the left pane, and open the “Users” settings:

Change Root Password In Ubuntu 24.04 Q

Step 2: Unlock the Settings

From the “Users” page, first unlock the settings, and then navigate to the Password option:

Change Root Password In Ubuntu 24.04 R

Step 3: Change Password

In the pop-up window, specify the current password, then set the new password, and finally click on the Change button to update the password:

Change Root Password In Ubuntu 24.04 S

That’s all about changing the root or sudo password in Ubuntu 24.04.

Final Thoughts

In Linux distributions like Ubuntu, changing the root password regularly helps us maintain the system’s security. You can change/reset the root password by logging in as a root user or as a regular user with sudo permissions. Alternatively, you can boot into recovery mode from the GRUB menu, access the root shell prompt, and execute the “passwd” command to change the root password. Similarly, if you forget your root password, you can reset it from the GRUB menu, as demonstrated in this guide.