UbuntuUbuntu Based

How To Change Root Password on Ubuntu 24.04 LTS

Change Root Password on Ubuntu 24.04

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:

    1. Open a terminal window.
    2. Type sudo passwd root and press Enter.
    3. Enter your current user’s password when prompted.
    4. Set a new password for the root account when prompted.
    5. Retype the new password to confirm it.
    6. 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:

    1. Reboot your Ubuntu system.
    2. When the GRUB menu appears, press ‘e’ to edit the boot entry.
    3. Find the line that starts with linux and append rw init=/bin/bash at the end of the line.
    4. Press Ctrl+X or F10 to boot with the modified parameters.
    5. Once booted, you will be at the root shell prompt.
    6. Type mount -o remount,rw / to remount the root filesystem in read/write mode.
    7. Type passwd to change the root password.
    8. Enter the new password twice when prompted.
    9. 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:

    1. Reboot your Ubuntu system.
    2. When the GRUB menu appears, select “Advanced options for Ubuntu” and press Enter.
    3. Choose the entry with “(recovery mode)” at the end and press Enter.
    4. In the recovery menu, select “Root – Drop to root shell prompt” and press Enter.
    5. Type mount -o remount,rw / to remount the root filesystem in read/write mode.
    6. Type passwd to change the root password.
    7. Enter the new password twice when prompted.
    8. 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:

    1. Boot from an Ubuntu live CD/USB.
    2. Open a terminal window.
    3. Type sudo mkdir /mnt/ubuntu to create a mount point for your Ubuntu installation.
    4. Type sudo mount /dev/sdXY /mnt/ubuntu, replacing sdXY with the actual device and partition of your Ubuntu installation.
    5. Type sudo chroot /mnt/ubuntu to change the root directory to your Ubuntu installation.
    6. Type passwd to change the root password.
    7. Enter the new password twice when prompted.
    8. Type exit to exit the chroot environment.
    9. Type sudo umount /mnt/ubuntu to unmount your Ubuntu installation.
    10. 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:

  1. Test the new root password by logging in as root or using the sudo command.
  2. Update any password managers or documentation where you store the root password.
  3. Review your system’s security settings and ensure that root login is disabled if not required.
  4. 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.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button