What to Do If You Forget Your Ubuntu Password

Updated: January 28, 2024 By: Guest Contributor Post a comment

Overview

If you’re an Ubuntu user, there’s a chance that you might forget your password. A forgotten password can be a hindrance to accessing your data and using your system. However, Ubuntu, like most modern operating systems, provides a way to reset a forgotten password.

In this tutorial, we will cover the methods you can use to reset your Ubuntu password. We will begin with the basic recovery mode option and proceed to more advanced methods, which can be helpful if the standard recovery approach doesn’t work for you.

Method 1: Reset via Recovery Mode

The simplest way to reset your password in Ubuntu is through the recovery mode.

  1. Reboot your Ubuntu PC and hold down the Shift key if your system uses a BIOS or keep pressing Esc if your system uses UEFI. This should bring up the GNU GRUB menu.
  2. Use the arrow keys to select the ‘Advanced options for Ubuntu’ and press Enter.
  3. Select the ‘Ubuntu, with Linux (your version) (recovery mode)’ entry and press Enter.
  4. A recovery menu will appear. Use the arrow keys to select ‘root – Drop to root shell prompt’ and press Enter.
  5. You will now be in the root shell. The filesystem will be in read-only mode, so you will need to remount it with write permissions using the following command:
    mount -o remount,rw /
  6. Now you can use the passwd command to reset your password. Replace ‘username’ with your actual username:
    passwd usernameIf successful, you'll be prompted to enter and confirm a new password.
  7. Once the password has been reset, reboot the system.
    reboot

Note: If you have encrypted your home directory or are using full disk encryption, the above method might not work, and you will need to use your encryption passphrase to decrypt your data after booting.

Method 2: Using a Live CD/USB

If you cannot access the recovery menu or if your home directory is encrypted, you can use an Ubuntu Live CD or USB to reset your password.

  1. Boot from an Ubuntu Live CD or USB.
  2. Open a terminal window and install chroot:
    sudo apt-get update sudo apt-get install chroot
  3. Find out the name of your Ubuntu partition using the ‘lsblk’ command. It usually is something like ‘/dev/sda1’.
    lsblk
  4. Mount the partition:
    sudo mount /dev/sda1 /mntNote: Replace '/dev/sda1' with your actual partition name.
  5. Bind the directories that chroot needs to access the filesystem:
    for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
  6. Enter the chroot environment:
    sudo chroot /mnt
  7. Use the passwd command to change your user’s password. Don’t forget to update the initramfs afterwards:
    passwd username update-initramfs -u
  8. Exit chroot and reboot:
    exit reboot

Warning: This will work for passwords but cannot decrypt an encrypted home directory or disk. For that, you will need your encryption passphrase.

Method 3: Single User Mode

This method is for more advanced users who are comfortable with editing the GRUB boot parameters.

  1. Reboot your Ubuntu PC and hold the key to enter the GRUB menu as covered in Method 1.
  2. Highlight the default Ubuntu entry and press e to edit the boot parameters.
  3. Find the line that starts with ‘linux’ and ends with ‘quiet splash’. Add rw init=/bin/bash at the end of this line.
  4. Press Ctrl+X or F10 to boot.
  5. You will boot into a single user shell with root access. Use passwd to change the password as in the previous methods and reboot with:
    passwd username exec /sbin/init

This will immediately boot you into your system with the new password set. Again, if your filesystem is encrypted, this method won’t resolve access to encrypted data.

Troubleshooting

If you experience issues while trying to reset your password, ensure that:

  • You have typed everything correctly, paying particular attention to spaces, slashes, and case sensitivity.
  • You are using the correct username and know the spelling used during the original installation.
  • Your keyboard layout hasn’t changed. Try typing your password where you can see it to ensure it’s what you expect.

Conclusion

Being locked out of your Ubuntu machine can be daunting, but as this guide shows, several methods can help you regain access. Whether you use the recovery mode, a Live CD/USB, or single user mode, each provides a pathway to reset your lost password and re-secure your system.