News
16th June 2015 | By:

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

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.

passwd pi

Make sure your changes are synced to the hard drive and are not sitting in the buffer.

sync

Start the normal booting process

exec /sbin/init

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

Tags: , , ,

Leave a reply

Your email address will not be published. Not now, not ever. Required fields are marked *

Comments


You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Name
Email
Website