At some point in time, everyone has forgotten or lost a password. If you ever have been in a situation where you cannot remember the password to login to a PC or server, it’s easy to start worrying about any data on the device and the stress of what would happen if you couldn’t access it ever again.
If you ever have this happen when working with a Linux device, no need to stress! There is a way to reset a local user account so you can get logged in and back to your data.
What you will need
For this guide, we’re going to assume you have the following in place:
- You currently have no way to login to the system as an Administrator. An example may be a test machine that you only created a single account, and that account is the one without a functioning password.
- An installed, working device with a Debian-based Linux, such as Ubuntu or Mint.
- For this guide, these steps were verified with Ubuntu 20.04 and Linux Mint 20
- For this guide, these steps were verified with Ubuntu 20.04 and Linux Mint 20
- Local “console” access to the Linux machine, either directly with keyboard/mouse/monitor, through a KVM switch, or using a Virtual Machine management console such as VirtualBox, VMWare, or HyperVM
- You normally log into the device with a local user account – not a network user account such as Active Directory, LDAP, Microsoft365, etc.
Steps to Reset a Lost Password
Boot , or reboot, your system. As soon as the system starts to load, press and hold down a Shift key.
The Shift key is a hotkey that tells the system we need some extra options during startup. We are attempting to get the following screen, called the GRUB Bootloader. On some systems the timing can be tedious, so it’s ok if it doesn’t work right away and finishes the normal boot process, taking you to the login screen. If this happens, just reboot and try again.
The common name you would recognize current system should be listed first in the list, with an asterisk (*) next to it. If it’s not first in the list, you can use your keyboard Up and Down arrow keys to move and highlight your system.
Once the correct entry is selected (highlighted), press the lower-case letter “e” on your keyboard.
You will now be on a screen where you can do some text editing:
Using the arrow keys on your keyboard, move the cursor down to the line that begins with:
linux /boot/vmlinuz-
The line you are looking for is usually close to the end.
Again, using the keyboard arrow keys, move your cursor to the end of the ending in:
quiet splash
You then will type to add the following at the end of the line.
rw init=/bin/bash
The text on the screen should now look as this:
Once your edits are completed, press F10 to reboot the system.
Instead of seeing the normal login prompts, you should instead see a command-line with the most recent text being:
root@(none):/#
We will now use the standard Linux command for changing a user account password. Type in “passwd”, then a space, then the username of the account you need to reset the password.
The generic format we use is:
passwd <username>
where “<username>” is substituted for the username of the account you need to reset the password. In our example, the username we need to reset is “sysdrive”, so the command used is:
passwd sysdrive
You will then be asked to type in a new password for the account. Be sure to follow good password habits and choose a strong one! One a new password is entered (and verified), you will receive a message the password has been updated.
Now it’s time to reboot your device. The easiest method is usually by pressing the Control, Alt, and Delete (Ctrl+Alt+Del) keys at the same time
Optional: When rebooting, you may see the GRUB Bootloader menu again. This is expected since we manually stopped it last time. If this does appear, make sure your same system is highlighted, then press the Enter key. You will also see a countdown timer that will automatically select the highlighted option if you do not press the Enter key.
Allow the system to continue booting, and you will be greeted by your expected login screen:
You can now enter the new password you chose a moment ago, press Enter, and enjoy re-gaining access to your device!