5 Easy Ways To Reset A Forgotten Password On Raspberry Pi


Forgetting your password is never a good experience, especially when it’s the main password, the one to unlock your operating system. But no worries, there are different ways to recover it (or rather reset it), and it doesn’t have to be complicated, unlike what other tutorials on this topic try to tell you.

Raspberry Pi OS has auto-login enabled by default, so most of the time, you can get access to the main user session without typing any password, and reset users passwords from there. If this isn’t possible, you can edit the /etc/passwd file to allow users to sign in without a password.

I thought of 5 ways to reset a password on Raspberry Pi, and I’ll now explain all of them, in order of the easiest method to the most complicated. So, go through this article in the logical order. If the first solutions don’t work in your situation, check the next one on the list.

If you are looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge, where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.

I answer your questions - Raspberry...
I answer your questions - Raspberry Pi FAQ

1 – Change your password via Raspi-Config or GUI

Download the Pi Glossary!
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!

Use this method if you have a desktop environment installed, and the session opens automatically on boot. In this case, you can directly change the password, without knowing the old one.

Once the session opens, go to Preferences > Raspberry Pi Configuration.
In the first tab, you’ll see a button to change the password for the current user:

It will ask you for a new password, without having to type the current one:

Raspberry Pi Bootcamp
Sale: 10% off today.
Take it to the next level.
I'm here to help you get started on Raspberry Pi.
Learn all the skills you need in the correct order.

So, this solution works even if you don’t know the current password.
It’s perfect if you’re still able to use your system, but have no idea which password to type when the system asks it for more permissions (when you install new applications, for example).

If you are on Raspberry Pi OS, you can use raspi-config to do the same thing. You’ll find the “Change password” item under the “System” menu.

If you are stuck on the login page, this method won’t help. But I prefer starting with the easy solutions first, so that you don’t break your system if there is no need to :-). Check the following solutions if this method didn’t work for you.

2 – Log in with another user to change the password

Use this method, if you created several users on your system, but lost the password for only one of them. If you have other users with administrator privileges, they can reset any user’s password on the Raspberry Pi.

Even if we generally use a Raspberry Pi with only one main user (pi or the one created during the installation), you can easily create new users for different roles and tasks, or even set a password for the administrator account (root).

If you had other users set up on the system where you forgot the password, you might be lucky! If you can access your system with another account that can use “sudo” to get administrator permissions, you can reset the password from there:

  • Get access to a command line (open a terminal, log in on a lite version or use SSH).
  • Type the following command:
    sudo passwd <username>
    For example:
    sudo passwd pi
  • You should get a prompt to set a new password for this user.
  • Once done, you can log out and sign in with this username and the new password you just set.

It only works if you have created other users on your system. If this isn’t the case for your system, take a look at the next option, which is the last “easy” one before we start editing files on your SD card.

3 – Use an SSH connection to access your account

Use this method if you can still connect to your Raspberry Pi via SSH because the password is saved on your client (or you use SSH keys), but have no idea what the password is. In this case, you can reset the password via SSH.

If, like me, you are using a smart SSH client (I use Termius) which saves all session credentials, you almost never type your password. And when you need it to install new applications, you might get stuck, as you don’t remember it.

how to use ssh on raspberry pi

It would be the same if you created SSH keys to log in from other computers without password authentication. In this case, you can still access your account on the Raspberry Pi, but have no idea what the password is.

Well, this is still an easy solution, as you can use the same command as in the previous solution to reset the password. Use raspi-config or type the following command to set a new password:
sudo passwd pi

Now that we have explored all the easy solutions when you still have a way to access your system, what can you do when you are stuck on the login page with no idea what the password is? The two last solutions will help you with this.

4 – Clear the password from another Linux system

Master your Raspberry Pi in 30 days
Sale: 10% off today.
Download the eBook.
Uncover the secrets of the Raspberry Pi in a 30 days challenge.
Learn useful Linux skills and practice multiples projects.

If you can access the SD card content from another Linux system, you can edit the /etc/passwd file from your Raspberry Pi system to allow you to log in to your account without any password. Use this method if you have no access to the current system, but can boot on another SD card or USB key to reset the password.

So, if you have a computer running Linux, just plug your SD card (or USB key) into it, and follow the instructions below.
If your computer is running Windows, you can’t edit the files on the SD card directly. In this case, your best option is to boot the Raspberry Pi with another media, and follow the instructions from there.

To give you an example, I have Windows on my computer.
So, I tested this solution with Raspberry Pi OS installed on a SD card (that’s the system where I forgot the password). I have a USB drive with Manjaro installed on it, so I booted it, and plugged the SD card once logged in on Manjaro. I can now follow the instructions below from Manjaro.

Whatever the way you choose, here is the procedure to edit the SD card content and disable the need of a password:

  • Plug the SD card on your computer or Raspberry Pi.
  • Open a terminal.
  • Mount the SD card main partition on the current Linux system.
    Some systems will do it automatically, on Manjaro I did this:
    sudo mkdir /mnt/sd
    sudo mount /dev/mmcblk0p2 /mnt/sd

    Check this article for more details on how to mount drives on Linux.
  • Once the partition is mounted, you can edit the /etc/passwd with something like:
    sudo nano /mnt/sd/etc/passwd
  • There is one line for each user on your system.
    Find the line corresponding to the user you lost the password.

    For example, if it’s “pi”:
  • Remove the “x” between the two colons.
  • Save and exit (CTRL+O, CTRL+X).

You can now halt your current (temporary) system, and boot again on the one where you lost the password.
In my case, I rebooted the Raspberry Pi, removed the USB key, and let only the SD card.

On the login screen, you can type the username (“pi” in my example) and it won’t ask for a password. The session will open directly. From there, you can set a new password, using the GUI, raspi-config or the command line directly:
passwd

Are you a bit lost in the Linux command line? Check this article first, for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.

Support me: Join the community on Patreon to show your support, get behind-the-scenes content and other awesome perks!

5 – Boot in single-user mode to reset the password (cmdline.txt)

Get My Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!

Use this method if all the other solutions are not possible for you. If you only have one SD card or USB key and no Linux system available, this is your best option (not the easiest, but it works).

The idea here, is to boot a minimal version of your system, with access to a command line as root. This way, you can use it to reset your password. It’s not straightforward, but it’s your best option if the previous solutions didn’t work for you.

First, insert the SD card (or USB key) on another computer. It can be any operating system (even Windows), it can even be another Raspberry Pi, it doesn’t matter.
In the boot partition, find the “cmdline.txt” file and open it, it looks like this:

Master Python on Raspberry Pi
Sale: 10% off today.
Get the eBook.
Do more with your Raspberry Pi, learn the useful concepts and take the shortcuts.
You miss half of the fun of using a Raspberry Pi if you don’t know anything about Python.

Just add the highlighted text at the end of the line, as in my screenshot:
init=/bin/sh
Save the file, and eject the media.
Put it back on your Raspberry Pi, and start it.

The system will boot almost as usual, but stop with a cursor, where you can type command lines.
The partition is not mounted automatically, so you will need to do it with:
mount -o remount, rw /

Warning: the keyboard layout will be in QWERTY, so good luck if (like me) you use another keyboard :-).

Once done, you can change the password with the same command previously used:
passwd <username>
For example:
passwd pi
We are logged in as root, so you don’t need “sudo”.

Make sure the changes are saved on the disk with:
sync
And then power off the Raspberry Pi (halt and reboot commands don’t work).

Before restarting the Raspberry Pi, you need to put the SD card back into your other computer, and remove the text you added in the cmdline.txt file.
So, remove “init=/bin/sh” at the end of the line, save the file, eject the SD card and put it back in your Raspberry Pi.

On the next boot, use the password you just set, and it should work.
That’s it! You can now continue with your main project, and don’t forget your password again :-).
And if you want to avoid losing your passwords all the time, you should check this project (it’s a password manager that you can host on a Raspberry Pi).

Raspberry Pi Resources

Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.

Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Download the e-book.

VIP Community
If you just want to hang out with me and show your support, you can also join the Patreon community. I share behind-the-scenes content there and give you early access to my content. You’ll also get a shoutout when you join.
More details here.

Need help building something with Python?
Create, understand and improve any Python script for your Raspberry Pi.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.

You can also find all my recommendations for tools and hardware on this page.


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

0 0 votes
Article Rating

Patrick Fromaget

I'm the lead author and owner of RaspberryTips.com. My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with a web developer experience.

Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Keith Bainbridge.
Keith Bainbridge.
3 days ago

Patrick, how do you get to pi-config if you can’t log in the first place?

Recent Posts