If you have lost you “pi” or “root” user password, the only way to rebuild the password is to reboot the Raspberry Pi in a special mode so that you can reset the password. To do this is to insert the card into a Mac or Windows machine and change the “cmdline.txt” file. Add init=/bin/sh to the end of the line.
Example:Before it might look like:
1 2 3 | dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait |
After adding the command it will look like:
1 2 3 | dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait init=/bin/sh |
Put the card back in the Raspberry Pi and start it. The system should start booting and then it will drop you at a command prompt. At this command prompt type:
1 2 3 4 5 6 7 8 9 10 | # mount -o remount,rw / # passwd pi (enter a new password) # sync # exec /sbin/init |
The boot process will then continue and then again drop you at a command prompt. Once it done you have to Re-edit the cmdline.txt file in /boot and now remove the init=/bin/sh from cmdline.txt.