forgot raspberry pi password

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’re feeling lost in all the Raspberry Pi jargon, I’ve got something to help you out. I’ve created a free glossary that explains all the essential terms and abbreviations in a way that’s easy to understand. It’s a great resource to have by your side. Get your free copy here.

Want the best experience? Become a premium member for ad-free browsing, access exclusive content, and ask questions in our private forums. Your membership helps support the site!

1 – Change your password via Raspi-Config or GUI

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:

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.

Related: 3 Ways to Remove Password on Raspberry Pi (+Security tips)

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

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.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

4 – Clear the password from another Linux system

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.

Download the Pi Glossary!
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
Download now
Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
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!

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

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:

I have an in-depth article on this website about cmdline.txt, and everything about it. I highly recommend reading it first, but I’ll give you the summary of what you can do to reset your password here.

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).

Whenever you’re ready, here are other ways I can help you:

The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.

Master your Raspberry Pi in 30 days: 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.

The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

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

How would you rate this article?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Spread the word!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Similar Posts

2 Comments

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

    1. Read the article :-).
      The first 3 solutions only work if you have a way to open a session (auto-login, other account or SSH session saved on your client).
      If not, you can try the two last ones.

Comments are closed.