How to Reset Raspberry Pi Password

Resetting a forgotten Raspberry Pi OS password is not too complicated. Here's what you need to do.
Warp Terminal

Don't remember the password you set while installing Raspberry Pi OS? It happens.

Raspberry Pi OS is set to auto login and doesn't even need password while using sudo. Since you are hardly entering the password anywhere, it is only human that you'll forget it.

Resetting the Raspberry Pi OS password is not complicated. In this tutorial, I'll cover both cases where you can auto login and where you cannot login to your system.

Let's start with the first method.

Method 1: If you can auto login

Here's the deal: By default, Raspberry Pi OS is set to automatically log in to the system without requiring a password.

If that's the case, you are in luck. Raspberry Pi OS is configured to not ask for a password with sudo. Since you can log in automatically, and no password is required for sudo, resetting the password will be super easy.

You just have to type this in the terminal:

sudo passwd username

Here's an example where I changed the password for the main user named ushika:

Changing password in Raspberry Pi

Alternatively, you can use the GUI tool provided by

Open Raspberry Pi Config tool

In here, under the System tab, you'll see the option to change the password.

Change Raspberry Pi password

Method 2: If you cannot auto login

This is slightly complicated and longer procedure. If you cannot log in to your Raspberry Pi OS, you can modify a few parameters to boot into the root shell and reset the password from there.

You need a separate computer, preferably running Linux here.

Step 1: Modify cmdline.txt file

Take out the micro SD card from the Pi and put it in your computer. On Linux, it should automatically mount. All you have to do is to edit the /boot/cmdline.txt file.

You can do it graphically or use the terminal; the choice is yours.

Edit the cmdline.txt file

There should be one or more lines and you have to add init=/bin/sh at the end of this last line, NOT on a new line. There must be a space before init=/bin/sh.

Now, this last line should look like this.

console=serial0,115200 console=tty1 root=PARTUUID=585e914d-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=IN init=/bin/sh

Save the file and unmount the SD card.

Step 2: Boot Raspberry Pi into the root shell

Plug the modified SD card into the Pi again and power it on.

Now when you boot into the Pi, it will drop you into the root shell. In here, you can run commands as root and make changes to your system.

Raspberry Pi Root Shell

But for that, you have to remount the system with read-write access (you must type the command exactly):

mount -o remount, rw /

Now, change the password for the user:

passwd username

If you do not remember the username, you can run ls /home/ and it should show what users are there on your system.

Enter the new password twice and then use this command to make sure that the changes are saved to the disk:

sync
Resetting Raspberry Pi Password

Everything seems to be set now. But you still have to revert the changes you made in cmdline.txt file otherwise you'll keep on booting into the root shell.

Use the command below to reboot into Raspberry Pi OS but temporarily bypassing the root shell:

exec /sbin/init

Once you are in your regular Raspberry Pi system, modify the cmdline.txt file again using this command:

sudo nano /boot/firmware/cmdline.txt
Revert the cmdline.txt changes you made earlier
Revert the cmdline.txt changes you made earlier

Remove the init=/bin/sh and press Ctrl+X to save the changes.

Next time you boot, you'll normally boot into your system.

Conclusion

There could be a few other methods for resetting the Raspberry Pi password. I came across them in various forum discussions. However, I find these two the most reliable options.

I hope this tutorial helps you reset the password on your Raspberry Pi OS. Let me know if you have questions.

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries πŸ•΅οΈβ€β™‚οΈ

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.