How To Change Root Password on Ubuntu 24.04 LTS
In this tutorial, we will show you how to change root password on Ubuntu 24.04 LTS. The root account in Ubuntu, like in other Linux distributions, is the most privileged user account with unrestricted access to the entire system. By default, Ubuntu disables direct root login and encourages users to perform administrative tasks using the sudo
command. This approach enhances security by minimizing the risk of accidental system changes and potential security breaches.
However, there may be situations where you need to change the root password, such as when you inherit a system from another administrator or if you suspect that the password has been compromised. Changing the root password is a straightforward process, but it requires careful execution to maintain the integrity of your Ubuntu system.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step change root password on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
- An Ubuntu 24.04 system with root access or a user with sudo privileges.
Change Root Password on Ubuntu 24.04 LTS Noble Numbat
Step 1. Updating the Package Repository.
Updating your system will fetch the latest package lists from the repositories and upgrade any installed packages to their newest available versions. To update your system, open a terminal window and run the following commands:
sudo apt update
The sudo apt update
command refreshes the package lists, while sudo apt upgrade
upgrades any outdated packages to their latest versions. If prompted, enter your sudo password and press ‘Y’ to confirm the installation of updates.
Step 2. Change the Root Password.
There are several methods to change the root password on Ubuntu 24.04. Each method is suitable for different scenarios, whether you have access to the current password or need to reset a forgotten one.
- Method 1: Using the
sudo
Command
The sudo
command allows users with administrative privileges to execute commands as the root user. Follow these steps to change the root password using sudo:
-
- Open a terminal window.
- Type
sudo passwd root
and press Enter. - Enter your current user’s password when prompted.
- Set a new password for the root account when prompted.
- Retype the new password to confirm it.
- If successful, you will see a message indicating that the password has been updated.
Example:
$ sudo passwd root [sudo] password for user: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
- Method 2: Using GRUB to Reset Root Password
GRUB (Grand Unified Bootloader) is the default bootloader for Ubuntu systems. You can use GRUB to reset the root password by modifying the boot parameters. Follow these steps:
-
- Reboot your Ubuntu system.
- When the GRUB menu appears, press ‘e’ to edit the boot entry.
- Find the line that starts with
linux
and appendrw init=/bin/bash
at the end of the line. - Press
Ctrl+X
orF10
to boot with the modified parameters. - Once booted, you will be at the root shell prompt.
- Type
mount -o remount,rw /
to remount the root filesystem in read/write mode. - Type
passwd
to change the root password. - Enter the new password twice when prompted.
- Type
exec /sbin/init
to reboot the system.
Method 3: Using Recovery Mode
Ubuntu’s recovery mode provides a way to perform system maintenance tasks, including resetting the root password. Follow these steps:
-
- Reboot your Ubuntu system.
- When the GRUB menu appears, select “Advanced options for Ubuntu” and press Enter.
- Choose the entry with “(recovery mode)” at the end and press Enter.
- In the recovery menu, select “Root – Drop to root shell prompt” and press Enter.
- Type
mount -o remount,rw /
to remount the root filesystem in read/write mode. - Type
passwd
to change the root password. - Enter the new password twice when prompted.
- Type
reboot
to restart the system.
- Method 4: Using a Live CD/USB
If you can’t access your Ubuntu system through the previous methods, you can use a live CD/USB to change the root password. Follow these steps:
-
- Boot from an Ubuntu live CD/USB.
- Open a terminal window.
- Type
sudo mkdir /mnt/ubuntu
to create a mount point for your Ubuntu installation. - Type
sudo mount /dev/sdXY /mnt/ubuntu
, replacingsdXY
with the actual device and partition of your Ubuntu installation. - Type
sudo chroot /mnt/ubuntu
to change the root directory to your Ubuntu installation. - Type
passwd
to change the root password. - Enter the new password twice when prompted.
- Type
exit
to exit the chroot environment. - Type
sudo umount /mnt/ubuntu
to unmount your Ubuntu installation. - Reboot the system and remove the live CD/USB.
After successfully changing the root password, it’s important to perform a few additional steps to ensure the security and proper functioning of your Ubuntu system:
- Test the new root password by logging in as root or using the
sudo
command. - Update any password managers or documentation where you store the root password.
- Review your system’s security settings and ensure that root login is disabled if not required.
- Consider implementing additional security measures, such as SSH key-based authentication or two-factor authentication.
Congratulations! You have successfully changed root password. Thanks for using this tutorial to change root password on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the Ubuntu website.