How to Reset a Forgotten Raspberry Pi Password


Occasionally I forget the Raspberry Pi password on my projects. It’s a pain but this guide provides a technique to reset the password and gain access to the system and get it back up and running. You need physical access to the SD card, a separate PC and the ability to connect your Pi to a monitor and keyboard. I used a Windows PC but this should work fine on a Mac or Linux machine.

Step 1 – Pi Password Recovery Requirements

Raspberry Pi Password

To use this technique you must :

  • Have physical access to the Pi and its SD card
  • Access to a keyboard and monitor
  • Suitable adapters if you are using a Pi Zero
  • Have a PC/laptop with a microSD card reader

Step 2 – Grab The SD Card

Power down the Pi and remove the SD card. Insert it into your PC.

Step 3 – Edit cmdline.txt

The boot partition should be visible and contain a file named “cmdline.txt”. Edit this file in a text editor and add the following to the end of the existing text :


If the original content was :

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=04ceb741-02 rootfstype=ext4 elevator=deadline rootwait

it should now look like :

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=04ceb741-02 rootfstype=ext4 elevator=deadline rootwait init=/bin/sh

Make sure it is all one line! Save the text file and eject the SD card from the PC.

Step 4 – Reset the Pi Password

Insert the card into the Pi with a monitor and keyboard connected. Power up the Pi. There may be a delay but you should be presented with a cursor.

At the prompt type the following command :

mount -o remount, rw /

If this results in an error message such as :

/bin/sh: 0: can’t access tty; job control turned off [ 21.366191] random: crng init done

simply try the mount command again :

mount -o remount, rw /

Finally you can now attempt to change the password :

passwd pi

You will then be prompted for a new password. Enter it carefully and press the [Return] key. It will now ask you to retype the password.

Reset Lost Password

The password has been changed.

Now type the following commands :

exec /sbin/init

The Pi will continue to boot and return you to the normal command line prompt.

Shutdown the Pi and power it off.

sudo halt

Step 5 – Edit cmdline.txt

Remove the SD card from the Pi and using the PC edit the “cmdline.txt” file again and remove the “init=/bin/sh” text you added in Step 2.

Safely eject the SD card from the PC and re-insert into the Pi.

Power up the Pi and your new password should now be active.

Now, don’t forget that password again!



  1. Or you could just edit the /etc/shadow file and remove the encrypted password string and then you can login without needing to enter a password. Then you use passwd to set it again.

  2. My Pi starts up as normal after adding the text to the existing line in cmdline.txt file. I never get the chance to type “passwd pi” – only the usual login is displayed. Is there another way?

    • Not that I know of. The only thing I can suggest is double checking the config.txt file and making sure every character is correct and that it only takes up one line.

    • I had the same problem. Even bought a new keyboard cause I read that it might not be picking up on my wireless one. In the end, init=/bin/sh was on another line. Try opening the file with leafpad. That’s how I discovered it was formatted wrong. Good Luck

  3. For those who like Henrik that its Pi boots to normal login prompt, I assume you’re editing in Windows and are using Notepad. That’s the problem.

    Notepad will place the new text in a new line although it will seem it’s in the same. That’s because Notepad needs a different end-of-line than UNIX-like systems (Windows text files use a CR+LF sequence, UNIX-like text files only use LF) and will show everything in only one line in a text file from a UNIX-like system.

    I haven’t tried to delete the last space or even the last character of the line and rewrite it again and then add ‘init=/bin/sh’. Don’t know if it will work.

    What does work is install Notepad++ and it will keep the correct formatting and character sequence of the original file. This will work!!

  4. Other solution : make a new SD card or USB Key with raspbian, boot on your favorit Linux and copy shadow from USB Key to your SD Card Pi.
    cp /mnt/USBKEY/etc/shadow* /mnt/SDcardPi/etc/

    It’s works now with default password ” raspberry”

  5. I was getting this type of error on my first attempt:

    passwd: Authentication token manipulation error
    passwd: password unchanged

    I did a bit of searching on the web and found that you have to re-mount the root directory where the shadow file is in order to be able to change the password. You can accomplish that by entering the following command:

    mount -o remount,rw /

    Thanks for writing this article!

  6. Michael Grant on

    I was getting this:

    # passwd pi
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: Authentication token manipulation error
    passwd: password unchanged

    I had to remount / read-write like this before I could change the password:

    mount -rw -o remount /

  7. Thanks for the help! Worked a treat, after I edited the cmdline in Notepad++. Knowing my luck I better save this in my favourites.

  8. I’ve tried this, and when I get past the “mount” stage, it tells me that there was an “error while loading shared libraries: /lib/arm- linux-gnueabihf/ ELF header”. Same error if I try exec /sbin/init, then a “Kernel panic”
    Any ideas?

  9. I have a Raspberry Pi B+ that I am pretty sure is running Raspian 4.0. I cannot find a file named “cmdline.txt”. Anyone know how to solve this problem?

    • Google “NOOBS”. I’m another noobie, so can’t cite specifics off the top of my head, but it has to do with the “NOOBS” install method hiding the part of the SD card that contains cmdline.txt.

      I’m in the same predicament right now and am trying to resolve it by tapping Shift while booting, which throws me into a “Recovery Mode” where I can edit the hidden cmdline.txt…. only problem is that the recommended appending of init=bin/sh has had the effect of hanging the boot process instead of getting me to a PW reset screen.

  10. So I have forgotten both my login and password. I was able to successfully change the password using this method, but am still stuck not knowing my login.

    How do I reset my login details? If I was able to reset my password, I don’t see why I couldn’t reset the login username too

    • Try: cat /etc/passwd

      This should print out all usernames, each on one line, together with other user’s data. Usernames are always the strings before the first colon on line.
      Eg. in:
      username is “pi”.

      (You can use: cut /etc/passwd -d : -f 1
      to print only usernames.)

      Most of the lines represents “virtual system” users, but Your username is also there (it will be probably near the end of the file).

  11. Hi,
    In my case with latest release this did’t work: “mount -rw -o remount /”
    But when I used this: “mount -o remount, rw /” all went fine 🙂

    • Thanks, I’ve updated the guide. I needed to follow this guide myself as I’ve just forgotten the Pi password on my pool monitoring system!

      • Hmm, I had to remove the comma between remount and rw statement in order for it to work.

        Great tidbit of information MATT. Thanks! It just saved my bacon. 😀

  12. David Glaude on

    If the remount fail and complain about PARTUUID, maybe your fstab is wrong, so use this:

    mount -o remount,rw /dev/mmcblk0p2 /

    It worked for me.

  13. If you have installed Raspbian via NOOBS, you can edit cmdline.txt from the boot menu. Just hold the SHIFT key at startup.

  14. One quick tweak would make this a little quicker: After the password is reset, you can just edit cmdline.txt from the command prompt (sudo pico /boot/cmdline.txt) instead of removing the SD card and editing it from another machine.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.