News

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.

cmdline.txt

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
[code language=”bash”]
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
[/code]
Modify the cmdline.txt and add the following init=/bin/sh
[code language=”bash”]
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait init=/bin/sh
[/code]
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.
[code language=”bash”]
mount -o remount,rw /
[/code]
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.
[code language=”bash”]
passwd pi
[/code]
Make sure your changes are synced to the hard drive and are not sitting in the buffer.
[code language=”bash”]
sync
[/code]
Start the normal booting process
[code language=”bash”]
exec /sbin/init
[/code]
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
References:
http://en.wikipedia.org/wiki/Init
http://linux.die.net/man/8/mount
http://man7.org/linux/man-pages/man1/passwd.1.html

Leave a Reply

Your email address will not be published. Required fields are marked *