Running a pi 4 with raspian. I dont have a password fro removing or installing software.

How do I reset it without having to delete everything and start again?

  • not Raspberry Pi specific ... it is a linux question
    – jsotola
    Sep 30, 2021 at 0:42
  • 1
    @jsotola: the recovery can be pi sepcific. Sep 30, 2021 at 8:55

3 Answers 3


If you have root on another linux box and an SD card reader, you can mount the SD card from the pi on that machine, and copy your hashed password from the local machine to the SD card.

You will find your local password in /etc/shadow as the second : separated field, or you can generate a new one with tools like htpasswd or openssl passwd -6

When you mount the SD card, the shadow file on the SD card would be something like /media/root/etc/shadow

Be sure to correctly eject the SD card before removing it.


Rebooting to a root shell and can repair most problems on the Pi.

  1. Append init=/bin/sh at the end of cmdline.txt and reboot.
  2. After booting you will be at the prompt in a root shell.
  3. Your root file system is mounted as readonly now, so remount it as read/write mount -n -o remount,rw /

You can then reset password with passwd pi although there are other methods e.g. deleting the password in /etc/passwd (which you will find if you search)

  1. Remove init=/bin/sh and reboot.

Some addition to @milliways's answer:

  • if you have lost root access to the Pi, you can take-out the SD card and use a different computer to edit the cmdline.txt
  • the cmdline.txt is on the first partition (or /boot)
  • instead of assigning a new password, you may also add

at the end of /etc/sudoers temporarily, assuming that you can mount the second partition somewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.