1. Home
  2. Linux

How To Reset A Forgotten Password On Linux

Forgetting the password to your Linux PC’s user account can be seriously annoying. It locks you out and prevents you from accessing anything. Not to worry! Contrary to popular belief, you don’t need to completely re-install your system and start everything over. You can reset a forgotten password on Linux, andĀ change the password to your username.

Root Password

One way to reclaim a user on a Linux system when you’ve forgotten the password is to use the Root account. As Root has ultimate control over the system, it’s possible to forcibly reset a forgotten password on Linux with it. Using Root to reset your password can be done without any new software, live disks, etc.

To start the process, load up your Linux system like you normally would, and let it load to the login screen. Don’t log in! Instead, press Ctrl + Alt + F2 to open up a TTY window. These TTY windows are emergency shells that users have access to regardless of logging in.

At the TTY window, you’ll see a prompt asking for a username. In the user slot, enter “root,” followed by the root password.

Note: if you are using Ubuntu, Linux Mint or another Linux distribution that disables su and the root account, this method will not work. Try the chroot method instead.

If the Root password is correct, the TTY window will log you in as a superuser, with complete power of the Linux system. At this point, you’ll be able to reset your user’s password:

passwd username

Running passwd asks you to enter a “new UNIX password”. Do so, and try to remember the password this time!

Now that your user’s password is reset, it’s safe to use the user account again. Use the reboot command to restart your PC and return to the login screen.

reboot

Upon restart, you should be able to log in.

Chroot

On some Linux distributions, the Root method for resetting a password will not work. This is due to the fact that some systems disable the ability to log in as su, and instead use sudo privileges for everything. On one hand, this is superior security, but in a pinch, you’ll miss out on helpful tricks.

As a result, it’s more complicated to reset a forgotten on Linux. The first step is to download the latest version of Ubuntu to create a live disk.

After downloading Ubuntu, download the Etcher tool and use it to make an Ubuntu live disk. Once the live disk is ready, plug in the USB drive, restart your PC and boot from it.

Once Ubuntu loads up, click “try Ubuntu”.

Set Up Chroot

Before resetting the password, we’ll need to set up a Chroot. A Chroot will allow Ubuntu to directly interact with the Linux operating system on your hard drive, with root access.

Open up a terminal and create a new folder inĀ /mnt. Be sure to label the folder the name of your OS. In this example, we’ll be using OpenSUSE LEAP.

sudo -s 

mkdir -p /mnt/opensuse-leap/

Next, run the lsblk command to determine what the drive label is. In this example, the hard drive is /dev/sda, and the OpenSUSE LEAP partition we need to mount is /dev/sda1. Yours may differ.

Mount your Linux installation’s partition to the new folder in /mnt. Be sure to change references to “opensuse-leap” to the name of your OS folder in /mnt.

mount /dev/sda1 /mnt/opensuse-leap/

With the system partition mounted, it’s time to link running Ubuntu services to the Linux OS on the hard drive.

mount -t proc proc /mnt/opensuse-leap/proc

mount -t sysfs sys /mnt/opensuse-leap/sys

mount -o bind /dev /mnt/opensuse-leap/dev
cp -L /etc/resolv.conf /mnt/opensuse-leap/etc/resolv.conf

With the Chroot setup, it’s time to access it. In the terminal, mount your operating system through the Ubuntu live disk with:

chroot /mnt/opensuse-leap /bin/bash

Check that you are indeed in the Chroot by running Neofetch or Screenfetch to display system info.

Finally, reset your user’s password with:

passwd username

When done, type exit a few times to close the Chroot session. From there, use the umount command to unmount your system partition from the live disk.

sudo umount /dev/sda1

The above command should unmount everything. If not, consider using the “force” option.

sudo umount /dev/sda1 -l

Now that the system drive is correctly unmounted, it’s safe to exit the live disk. Click the menu on the top-right inside the Ubuntu live disk, then select “reboot”.

Remove the Ubuntu USB stick and let your Linux PC restart. When it restarts, your password will be reset!

Leave a comment