forgot ubuntu password

Assuming your system is not encrypted, you can reset the password within a couple of minutes. There are multiple ways to go about it from the recovery mode to using a live USB.

If this is your first time learning about this, you might be understandably surprised. Linux, the platform that’s praised for being secure, is so easy to breach?

The thing is, if you have physical access to an unencrypted device, it might as well have no protection. And this is true for most platforms.

But we’ll leave the security discussion for another day. Here, we’ll just focus on how you can reset a forgotten password on Ubuntu.

Reset from Recovery Mode

Recovery mode is normally used for repairing your system as root. It’s also the standard way to reset forgotten passwords on Ubuntu. You may be prompted for the root password though. If you’ve forgotten the root password as well, try the other methods.

Step 1: Boot into Recovery Mode

Power on your PC and hold Shift when booting for BIOS systems. With UEFI, repeatedly press Esc instead. This’ll bring up the GRUB menu.

Select Advanced options for Ubuntu and then boot with the Recovery Mode entry.

Step 2: Mount Root with Write Access

In the Recovery Menu, you can see that the filesystem state is read-only. We’ll need write access to reset the password.

Select the root – Drop to root shell prompt option and press Enter.

Enter your root password if prompted, then mount the root partition as read-write.

mount -rw -o remount /

Step 3: Reset the Password

List the users if required with

ls /home

Set a new password for the desired user like so

passwd anup

After updating the password, restart your machine.

shutdown -r now

Run Bash as Init

Typically, the kernel runs an init program at startup which is responsible for starting all other processes. You can instruct the system to run the bash shell at startup instead. This’ll let you access the filesystem as root in read-write mode, ultimately letting you change the forgotten password.

Note: Sometimes, the bash shell will not register any keystrokes if the init system is unable to load the keyboard properly. In such cases, try the other methods instead.

Step 1: Edit GRUB Entry Config

Like earlier, hold Shift or repeatedly press Esc when booting to bring up the GRUB menu.

Select Advanced options for Ubuntu and press Enter. Highlight your image and press E to edit it.

Change ro to rw. Then, append init=/bin/bash to the boot loader’s boot entry (look for the Linux line).

This’ll instruct the kernel to run /bin/bash at startup and mount the filesystem in read-write mode.

Press F10 to boot with this configuration.

Step 2: Change the Password

Update the password like so

passwd anup

In some cases, you’ll need to use the sync command to apply the changes.

sync

Finally, reboot your system with

shutdown -r now

Reset Password With a Live USB

If the prior methods didn’t work, you can boot from a Live USB, chroot to change the apparent root directory, and change the password.

Step 1: Boot from USB

Any Linux ISO should work as long as the ISO matches your instruction set architecture (x86, ARM, etc.). We’ll use the AMD64 Ubuntu ISO in our case.

  1. Connect a USB stick (4 GB or higher) to another system. Download the Linux ISO on that system and burn the ISO onto the stick with a tool like Rufus or Etcher.
    balena etcher ubuntu iso
  2. Connect this bootable USB to your own system and power on the PC.
  3. When booting, press the Boot or BIOS keys (Esc, F2, F10, F12, etc.) as shown on the screen. Select the USB Stick and place it at the top of the Boot Order.
    boot order usb drive
  4. Press the key shown on the screen (usually F10) to save the changes and exit. The system will now boot from the USB.
  5. Select the Try Ubuntu or similar option.
    install-ubuntu-try-ubuntu

Step 2: Mount Filesystem and Change Root

Launch the Terminal and login as root with

sudo su

Find the root partition’s filesystem with

df -hT

Mount the filesystem to the /mnt directory. Remember to replace /dev/nvme0n1p7 with your own value.

mount /dev/nvme0n1p7 /mnt

Change the root directory to /mnt.

chroot /mnt

Step 3: Reset the Password

Change the password like so.

passwd anup

Exit chroot, unmount the /mnt directory, and restart your system. 

exit
umount /mnt
shutdown -r now

Finally, remove the USB when prompted and press Enter to boot normally.

Anup Thapa

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.