logo of Akmatori
27.11.2024

How to Reset the Root Password on Ubuntu Linux

head-image

Forgot your root password? Don’t worry. This guide shows how to reset it on Ubuntu Linux. We’ll guide you through recovery mode or a live environment.

Prerequisites

Before starting, ensure you have:

  • Physical access to the Ubuntu machine.
  • Basic familiarity with command-line operations.
  • Backup of any critical data.

⚠️ Note: Use this method only on systems you own or manage. Unauthorized access violates ethical and legal standards.


Method 1: Reset via Recovery Mode

Step 1: Boot into Recovery Mode

  • Restart your system.
  • Hold down the Shift key to access the GRUB menu during boot.
  • Select the recovery mode option (e.g., Ubuntu, with Linux x.xx.x (recovery mode)).

Step 2: Access the Root Shell

  • In the recovery menu, select Drop to root shell prompt.
  • A shell will appear with root access.

Step 3: Remount the Filesystem as Read/Write

The filesystem is mounted as read-only by default. Run this command to remount it as read/write:

mount -o remount,rw /

Step 4: Reset the Root Password

Use the passwd command to set a new root password:

passwd

Enter the new password twice when prompted.

Step 5: Update the Filesystem and Reboot

Ensure all writes are committed and reboot:

sync
reboot

Your root password is now reset!


Method 2: Reset via Live USB

If recovery mode isn’t accessible, use a live USB.

Step 1: Boot from a Live USB

  • Create a bootable Ubuntu USB.
  • Insert the USB, restart the system, and boot from it (you may need to configure your BIOS/UEFI settings).

Step 2: Identify and Mount the Root Filesystem

Open a terminal and identify the root partition using lsblk:

lsblk

Mount the root filesystem (replace /dev/sdXY with your root partition):

sudo mount /dev/sdXY /mnt

Step 3: Chroot into the Mounted Filesystem

Change the root directory to the mounted filesystem:

sudo chroot /mnt

Step 4: Reset the Root Password

Use the passwd command to reset the root password:

passwd

Exit the chroot environment:

exit

Step 5: Reboot into Ubuntu

Unmount the partition and reboot:

sudo umount /mnt
sudo reboot

Your root password is reset and ready to use.


Best Practices for Root Account Security

  • Use a Strong Password: Combine uppercase, lowercase, numbers, and symbols.
  • Enable SSH Key Authentication: For remote access, use SSH keys instead of passwords.
  • Limit Root Login: Use sudo for administrative tasks instead of direct root access.

Ready to Optimize Your Linux Operations?

Efficient server management is critical for reliability. BrendanAI simplifies operations for DevOps and SRE teams by predicting failures, assisting in root cause analysis, and ensuring system resilience.

Try BrendanAI today and build more reliable Linux environments.


Conclusion

Resetting the root password on Ubuntu Linux is straightforward with recovery mode or a live USB. Always prioritize system security after resetting your password.

Let us know if this guide helped you. Leave a comment or check out our other Linux tutorials!

Maximize your website or application's performance and reliability!