RasPi /
LostPassword
Losing one's password makes life difficult. With a RasPi, recovery without losing the OS content isn't too hard. If, that is, you have physical access to the system.
- Remove the SD card
- Mount the SD card on another computer (that you DO have access to)
- Edit the
cmdline.txt
file in the boot partition, changing the line that resembles
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
to
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait init=/bin/sh
Note that the added text init=/bin/sh
must be on the same line as the original command
- Attach, at minimum, a keyboard to the RasPi. Attach a display if possible (it will make this easier)
- Put the SD card back in the RasPi and power it up
- Wait for the RasPi to boot. At the end of the boot process, it will open a shell and allow input. With a display, you will see this. Without, you get to wait a good long while, then type blindly!
- Type
passwd pi
and enter - Type the new password plus enter twice
- Type
sync
enter - type
exec /sbin/init
enter - Wait at least 30 seconds, then power down the RasPi
- Remove the SD card, edit on another computer, and restore the line in
cmdline.txt
to its original state - Put the SD card back in the RasPi, turn on, and enjoy the new password!