lost password linux

How To Easily Reset a Forgotten Password On Linux (2 ways)

Losing a password is never good news, but losing it on Linux, especially if it’s the administrator password, can be a real disaster. Don’t worry, I’ve got it covered. Whatever your situation, I’ll show you how to reset a password quickly on any Linux distribution.

To reset a normal user password on Linux, a root session can be opened to do it from there. To reset the administrator password, the computer must be started in recovery mode to get access to the terminal without the password.

I will show you both methods in this article. The first one is easier, but only works if you know the root password. The second is a bit tricky, but works even if it’s the administrator account that you need to reset.

Linux doesn’t have to be intimidating. With my e-book, Master Linux Commands, you’ll uncover the secrets of the terminal in a fun, step-by-step journey. From basics to scripts, get ready to level up your Linux skills. Oh, and did I mention the handy cheat sheet you get as a bonus?

Method 1: You know the root password

The first solution is to exit the desktop environment and open a session with root from a terminal. Once logged in, you can use the “passwd” command to reset the password of any user on the computer.

Join Our Community!

Connect, learn, and grow with other Raspberry Pi enthusiasts. Support RaspberryTips and enjoy an ad-free reading experience. Get exclusive monthly video tutorials and many other benefits.

Learn more

With most Linux distributions, opening a new session with the administrator account in the graphic environment is not allowed. So, if you have a desktop environment, the first step is to switch to a terminal.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

You can do this with a combination of keys. In general, it’s something like “CTRL+ALT+F2”.
If it doesn’t work, try another F key (CTRL+ALT+F1, CTRL+ALT+F3, etc.). I tested it on Debian, F1 is the graphic interface, while F2, F3, etc. are available for a terminal session.

You should get to a black screen with a login prompt.
Enter “root” for the login, press “Enter” and type the password followed by “Enter” again to log in. It will look like:

Once logged in, you have full access to your system and can use any command you need.
To reset the password of a user account, you can simply type:
passwd <username>

Type the new password twice and you’re done. You can switch back to the graphic interface (CTRL+ALT+F1 on Debian, can be F7 on other distributions), and test to sign in again.

If you can’t figure out how to return to the desktop environment, just restart the computer with the command:
reboot

The interface will start automatically, and you can log in again with the new password.

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now
Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Method 2: Reset the root password

If you don’t have the root password, you won’t be able to use the first method. An alternative would be to have access to an account with sudo privileges, so you can follow the first method by switching to root from a standard user session.

But I guess you don’t have this option, so we’ll need something else.

It’s possible to start Linux in recovery mode by editing a command in the bootloader (GRUB) and starting the system with only access to bash. From there, we can run a few commands to reset the root password.

Here is the procedure to do this. I’m testing this on Debian, but it should be similar on most distributions (Ubuntu should be identical):

  • Restart the computer.
  • Wait for the boot menu (GRUB), but don’t let it start automatically.
    Pressing the up and down arrow keys will stop the countdown.
  • Select the default option (“Debian GNU/Linux” in my example) and press “e”.
  • A text will show up, with the commands used to start the system.
    Find a line starting with “linux” and add this at the end:
    init=/bin/bash
  • Here’s what it looks like once done:
  • Press CTRL+X or F10 to start the computer with this additional parameter.

The boot process will start, but will quickly stop.
You’ll get access to a minimal terminal, already logged in as root:

From there, you get access to the file system, but it’s mounted in read-only mode.
You can change that with this command:
mount -n -o remount,rw /

You now have access to the full file system, and can even use this command to change the root password:
passwd

Type the new password twice, and then restart the computer with:
reboot
Or, you can also press CTRL+ALT+DEL.

On the next boot, the system will start normally (your changes in GRUB are temporary) and you can now use root from the terminal, or reset your main user password following method 1 if needed.

From there, whatever method you used, it’s probably a good idea to put some safety nets in place, like creating another user with sudo access or using a password manager, so you don’t forget it again.

Now that you’ve recovered access to your Linux computer, here are a few articles you should read next:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

If you are looking for exclusive tutorials, I post a new course each month, available for premium members only. Join the community to get access to all of them right now!

Additional Resources

Overwhelmed with Linux commands?
My e-book, “Master Linux Commands”, is your essential guide to mastering the terminal. Get practical tips, real-world examples, and a bonus cheat sheet to keep by your side.
Grab your copy now.

VIP Community
If you just want to hang out with me and other Linux fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Python is a great language to get started with programming on any Linux computer.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.

Similar Posts