Skip to Content

How to reset a forgotten Raspberry Pi password: SD card method

Step-by-step password recovery for Raspberry Pi OS, the Raspberry PLC, the GateBerry and the TouchBerry Pi, with no data loss
June 18, 2026 by
How to reset a forgotten Raspberry Pi password: SD card method
Joan F. Aubets - Industrial Shields

Complete guide: Choosing an industrial controller

To reset a forgotten Raspberry Pi password without reinstalling the operating system, take out the microSD card, add init=/bin/sh at the end of the single line in cmdline.txt on the boot partition, and start the device. It boots to a root shell. Run mount -o remount,rw /, then passwd followed by the user name, then sync. Power off, remove init=/bin/sh from cmdline.txt and start again: the new password works and no data is lost. The method works on any device with Raspberry Pi OS on a microSD card, including the Raspberry PLC, the GateBerry and the TouchBerry Pi.

You need physical access to the microSD card, a second computer with a card reader, and a monitor and keyboard on the Raspberry Pi device.

Which method should you use?

SituationMethodData kept
You can still log in with another user that has sudosudo passwd usernameYes
You can log in over SSH with a keysudo passwd username in the SSH session, only if sudo does not ask for the forgotten passwordYes
No user can log inSD card method (this guide)Yes
The card is damaged or you want a clean systemWrite a new image with Raspberry Pi ImagerNo

Step by step: reset the password with the SD card

1. Edit cmdline.txt on another computer

Power off the device and remove the microSD card. Put it in the card reader of your computer. The boot partition (FAT32) opens on Windows, macOS and Linux without extra tools. Open cmdline.txt with a plain text editor. The file has one line only. Add a space and init=/bin/sh at the end of that line, without pressing Enter:

console=serial0,115200 console=tty1 root=PARTUUID=4daa237a-02 rootfstype=ext4 fsck.repair=yes rootwait init=/bin/sh

Your line will have a different PARTUUID and maybe other options. Do not change them: only add init=/bin/sh at the end.

2. Boot to a root shell

Eject the card safely, put it back in the device and power it on. Instead of the login prompt, you get a root shell (#). A message such as can't access tty; job control turned off is normal: with init=/bin/sh there is no terminal control, and you can ignore it.

3. Make the file system writable

mount -o remount,rw /

4. Change the password

passwd pi

Replace pi with your user name. Recent versions of Raspberry Pi OS have no pi user by default: the user is created at the first boot or in Raspberry Pi Imager. If you do not remember the name, list the users with a home folder:

ls /home

Type the new password twice. Nothing appears on the screen while you type.

5. Save the changes and power off

sync
mount -o remount,ro /

Then disconnect the power. The usual halt or poweroff commands may not work, because the normal init system is not running.

6. Restore cmdline.txt

Put the microSD card in your computer again, delete init=/bin/sh from cmdline.txt and save. Put the card back in the device and power it on. It boots normally and accepts the new password.

On Raspberry Pi OS Bookworm and Trixie, the same file is at /boot/firmware/cmdline.txt when the system is running. On older versions it is at /boot/cmdline.txt. From another computer you always see it at the root of the boot partition. See the Raspberry Pi configuration documentation for the kernel command line.

On a Raspberry PLC, GateBerry or TouchBerry Pi

The Raspberry PLC, the GateBerry and the TouchBerry Pi of Industrial Shields run a Debian based Linux on a Raspberry Pi, with the same partition layout as a standard Raspberry Pi board, so the steps above are the same. The only difference is the access to the microSD card slot, which depends on the model: check the datasheet of your device. Connect a monitor and a USB keyboard to the device for steps 2 to 5.

A device installed in a cabinet often has no monitor nearby. If you can still reach it over the network, SSH access with a second admin user or a key is faster than the SD card method.

Password and access rules for devices in the field

  • Use a password of at least 12 characters with letters, numbers and symbols, different for each device.
  • Never leave a default password, such as the old raspberry, on a device in production.
  • Use SSH keys and disable password logins in /etc/ssh/sshd_config with PasswordAuthentication no, after you check that your key works.
  • Install fail2ban (sudo apt install fail2ban) to block repeated failed logins.
  • Keep the credentials of each device in a password manager, not in a shared spreadsheet.
  • Remember that anyone with physical access to the microSD card can use this method. Keep the cabinet locked.

FAQ about resetting a Raspberry Pi password

What is the default password of a Raspberry Pi?

Older Raspberry Pi OS images had the user pi with the password raspberry. Current images have no default user: you create the user and its password at the first boot or in Raspberry Pi Imager.

Does this method delete my programs or data?

No. It only changes the password of one user. Programs, configuration and data stay on the card.

Does it work on Raspberry Pi OS Bookworm and Trixie?

Yes. Edit cmdline.txt at the root of the boot partition from another computer, as in step 1.

Can I reset the root password the same way?

Yes, with passwd root in step 4. On Raspberry Pi OS the usual practice is to keep root locked and use sudo with a normal user.

The device does not boot after the change. What should I check?

Check that cmdline.txt still has one single line and that init=/bin/sh was added with a space before it and nothing else changed.

Take it further

With access to your Raspberry Pi again, see what a Raspberry PLC does in a real project, in a simulator and as a stack of containers.

​Search in our Blog

How to reset a forgotten Raspberry Pi password: SD card method
Joan F. Aubets - Industrial Shields June 18, 2026
Share this post
Tags

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

PLC Comparison