I have made several personal configuration changes to a Raspbian Wheezy install (more secure ssh, personal configurations, etc). It's been a couple weeks since I last touched it, and I completely forgot the password to login. What should I do?


5 Answers 5


Right off the bat, let me say that there is not a way to recover a password (without some actual cracking/hacking which I don't know how to do). Resetting your password is your best bet.

So the first step will be to determine if you have any way to log in to the Raspbery Pi.

If you're able to log in with a user that has 'sudo' rights (this includes SSH... perhaps you have keys set up properly but forgot the actual user password, which I ran in to), simply typing:

sudo passwd

should prompt you to create a new password (without having to enter your current password).

Another option would be to run the starting config and change the password that way.

sudo raspi-config

If you're completely locked out, you can try the technique mentioned here, though I didn't have any success with the strategy. It just kept me from finishing booting up the RPi.

I haven't found any good techniques to enable root access period (putting the conversation of why you'd even want to do that aside :) ), let alone if you can't log in. Somebody can correct me if I'm wrong.

Hopefully this will save you from blowing away an image with a fresh one. If this saves one person, figure it's worth the time to post :)

  • Strangely 'sudo pwd' did not work for me (additional permissions needed?), but interactive sudo 'sudo -i' session and then just pwd did work. So thanks for help
    – user14087
    Commented Aug 10, 2014 at 10:24
  • @user14087 It should be passwd, not pwd. Updated answer to show this.
    – Parker
    Commented Sep 24, 2014 at 16:26
  • "without some actual cracking/hacking" -- In fact there's no way to do that either beyond random guessing (aka. brute force); passwords are not stored on the system. Only a one-way hash of them is (emphasis on one-way).
    – goldilocks
    Commented Aug 19, 2015 at 18:17
  • 3
    The questioner probably wants to reset the password for the account "pi". If you have forgotten that password, but have SSH key access, logon and use this command: sudo passwd pi If you omit the "pi", you will be changing the password for the root account.
    – Jamie Cox
    Commented Apr 25, 2016 at 14:51

Mount the SD card, go into the file system, and edit /etc/passwd. Find the line starting with "pi" that begins like this:


Get rid of the x; leave the colons on either side. This will eliminate the need for a password.

You probably then want to create a new password by using the passwd command after you log in.

  • this method worked very well, thank you - changing the encrypted password to * didn't work, and the adding a init=/bin/sh method was useless... +1
    – Wilf
    Commented Jun 6, 2014 at 16:26
  • 2
    I can not say if this method worked in the passed but it certainly does not work now.
    – theAlse
    Commented Apr 24, 2018 at 5:07
  • This worked for me. RPi3B+ Raspbian 9.4 (stretch)
    – dparkar
    Commented Jul 13, 2018 at 4:20
  • 9
    This didn't work for me. However, a simple solution was just to add my client's public ssh key into the mounted pi's sd card's /home/pi/.ssh/authorized_keys. Then it is possible to ssh in and run passwd as normal
    – UsAaR33
    Commented Aug 4, 2018 at 2:30
  • @UsAaR33 Your comment is so far the best answer in the context of headless pi. Thanks a lot! You should add it as a separate answer! :)
    – mg007
    Commented Mar 15, 2021 at 18:29

If you have physical access to the pi, look at these instructions. Essentially, mount the SD card using a different machine and edit cmdline.txt to include (at the end) init=/bin/sh. Then, run the following commands:

mount -o remount,rw /
passwd pi
(enter a new password)
exec /sbin/init
  • Thanks for the info. I'm using Raspbmc and this was the only solution that worked for me. Commented Dec 21, 2014 at 19:20
  • 2
    If you get an error running the mount command, run this instead: sudo mount -o remount,rw /dev/mmcblk0p2 / Commented Sep 10, 2021 at 22:32
  • @TheBicPen you saved my day. I tried this command but with different arguments. The comment above is underrated ^^^^ Commented 4 hours ago

As Jamie Cox commented in one answer and what actually worked for my problem, you might want to change the password for the pi user, so type

sudo passwd pi

otherwise you are just changing the password for root.


I assume you have physical access to your SD.

Create new password: openssl passwd -6 -salt salt hello-world

You will receive something like: $6$salt$phlWRlSMVXZ1JJxGL/j5ANI.m8sbGpNT5pQE8iyx2TxYPKIZZhPM.eMN0axmoRHY3CrZU2KeyhTOcjBkKeD.N/

Edit /etc/shadow on your Pi's SD's root partition and replace the encrypted password with newly generated or edit /etc/rc.local and say "echo 'pi:password' | chpasswd" or "echo 'pi:<generated-password>' | chpasswd -e"

  • 2
    I had no HDMI adapter for the RasPi 4, so the above answers did not help (I'm sure they work, but they require being connected directly to the Pi, they do not work over SSH). I ran Linux Mint in a VM and followed your steps, it was straight to the point. Thanks.
    – nurchi
    Commented Oct 8, 2020 at 14:19

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