16th June 2015 by aegeuana_sjp_admin
Recover raspberry pi password
Raspberry Pi is an amazing and powerful tiny computer, we are actively using this device for our projects, recently we had run into an issue where we had forgotten the “pi” user’s password. This quick tutorial explains step by step what you need to do in order to change/recover the password.
Insert the SD card into a computer/laptop, once it is detected your should have a file named cmdline.txt, the purpose of this file is to add additional arguments to the kernel during the boot process. The file is located in /boot/ directory and by default it contains something in the lines of
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Modify the cmdline.txt and add the following init=/bin/sh
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait init=/bin/sh
The init instruction tells the kernel to spawn the initial process, in our case we want a simple shell. Save the file and boot your raspberrypi with the modified SD card.
Once your Raspberry Pi starts booting you shoudl directly get a shell command prompt.
At this stage you are actually logged in as root.
Perform the following commands
Mount the main partition so you can see all your files in read/write mode.
mount -o remount,rw /
As root you can now change the password of any user, in our case we want to change the password of “pi” user, follow the instructions of the passwd command.
Make sure your changes are synced to the hard drive and are not sitting in the buffer.
Start the normal booting process
At this stage you should be able to login as user “pi” with the new recovered password. Shutdown the Pi and edit again the cmdline.txt, make sure you remove the init=/bin/sh