The first step is to turn off the Raspberry so you can remove the memory card without worry.
If the Raspberry Pi is not connected to a screen, the only way to turn it off is to unplug it. Otherwise, you can go through the GUI to turn it off properly, via the menu, before unplugging it.
Once the Raspberry Pi is turned off, you can insert the card into your computer and go to the next step.
Open the file browser on your computer and go to the memory card. You will find in it a file named cmdline.txt
.
This file should contain a line of text that resembles the line below.
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
You must modify this file so that the Raspberry Pi starts on the bin/sh
script, which will allow you to change the password of your Raspberry Pi without knowing it!
To do this, simply add the line below to the end of the file and save it.
init=/bin/sh
WARNING: The text must imperatively be on the same line. It is possible that the “block note” editor will display it on the same line while it is not, consider checking with another text editor (eg sublimtext).
Once the file has been modified, you can safely disconnect the memory card from the computer and reinsert it into the Raspberry Pi.
It is in this part that you will need a screen and a keyboard for your Raspberry Pi. So connect your keyboard and your screen to the Raspberry Pi and start there.
A series of command lines should scroll quickly. After a few tens of seconds, the screen will be completely frozen. You should now be able to type text.
We will now mount the root of the system. To do this, run the following command :
mount -o remount, rw /
All you have to do now is to change the password of the Raspberry Pi. To do this, simply type the following command and follow the steps on the screen (note that for security reasons the password may not appear when you type it):
passwd pi
Once the password is changed, run these commands:
sync exec /sbin/init
The Raspberry will go out. Wait until the screen has completely frozen for at least 30 seconds and unplug it!
Remove the SD card from the Raspberry Pi and put it back in your computer.
Edit the cmdline.txt
file again the init=/bin/sh
part you previously add.
Put the SD card back into your Raspberry Pi and restart it. You should now be able to log in with the new password!
Now you know how to retrieve the lost password of your Raspberry Pi and retrieve access to your system!
Source: https://howtoraspberrypi.com/recover-password-raspberry-pi/
I encountered some issues after following this guide. The filesystem got somehow corrupted. Fixed issuing the following commands:
df -T
orfdisk -l
bootfs
androotfs
/dev/sdb2
)