How To Reset A Forgotten Raspberry Pi Password


I’ve got a Raspberry Pi running in my garage as part of a security system. It’s been running for so many months that I forgot the password so I was unable to access it via SSH.

Luckily there is was a technique that I could use to reset the password 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 – Grab The SD Card

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

Step 2 – 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=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

it should now look like :

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 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 3 – Reset the Password

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

At the prompt type the following command :

mount -rw -o remount /


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 4 – Edit cmdline.txt

Using the PC edit the “cmdline.txt” file again and remove the “init=/bin/sh” text you added in Step 2.

You can now return the SD card to your Pi, reboot and use the new password.




  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

Leave A Reply