Monday, October 18, 2021

RECOVERY PASSWORD Raspberry Pi - Do not Panic


We have a lot of things going on every day, sometimes we forget appointments or some anniversaries. But who did not forget passwords? 

Here I will show how to recover your password of your Raspberry Pi (RPI).  

PREREQUISITES

  • Physical access to RPI.
  • A computer with Windows or Linux or MacOS.
  • Adapter to connect microSD to the computer.
  • Keyboard and screen (HDMI) to connect RPI.
STEP 1. Turning off 

1. Turn off the RPI. 

If you have access to a GUI (monitor+keyboard) you can try to turn off the RPI safely, but if you don    have access or do not have a GUI installed just UNPLUG IT :(. 

2. Extract the microSD from the RPI. 

STEP 2. Single-Process mode

1. Connect the microSD card to the computer through the adapter if you need it. 

2. in your computer navigate to the microSD card and you will find the file cmdline.txt 

3. Edit the file adding to the end that you want to start in single-process mode

init=/bin/sh

you should have something similar to this line 

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait init=/bin/sh

4. keep on eye that the cmdline.txt will maintain its structure of ONE LINE file. 

5. Save the file and put in the RPI.

STEP 3. Change the password

1. Connect your monitor and keyboard to the RPI and boot it. (if your keyboard is not working go to the PROBLEMS section down in this page)  

2. Mount the system file 
mount -o remount, rw /

3. Now you just have to change the password
passwd pi 

4. Once you set the password run these lines
sync
exec /sbin/init

5. The screen will turn dark but wait at least 30 seconds. 

STEP 4. REVERT cmdline file

1. Unplug the RPI, take out the microSD and connect to your computer, 

2. Edit the file cmdline.txt and delete the part that you added in step 2.3. 

3. Save the file and eject safely the microSD and put it back to the RPI. 

4. You should be able to login with your new password  (step 3.3.)

5. Done!

PROBLEMS

you might have the problem that init=/bin/sh do not work because the OS do not enable your keyboard. :( DO NOT PANIC we have two more options:

OPTION 1.

Instead you append init=/bin/sh to the cmdline.txt file try to append

systemd.unit=emergency.target

OPTION 2. 

If option 1 did not work you should append this line to the same file 

systemd.unit=rescue.target

after you have keyboard now change the password in the console with 

sudo passwd pi 



Pi Fr, R. (2018, March 14). How to recover the password of your Raspberry Pi if you lost it. 2018 Update. –. Howto Raspberry Pi. https://howtoraspberrypi.com/recover-password-raspberry-pi/

Resseting password using init=/bin/sh - Keyboard doesn’t work. (2018, June 19). Raspberry Pi Stack Exchange. https://raspberrypi.stackexchange.com/questions/85146/resseting-password-using-init-bin-sh-keyboard-doesnt-work


No comments:

Post a Comment