antony96
Posts: 3
Joined: Fri May 11, 2018 1:04 pm

Password Lost

Mon Jun 18, 2018 12:37 am

Help I forgot my password

User avatar
The Traveler
Posts: 363
Joined: Sat Oct 21, 2017 3:48 pm

Re: Password Lost

Mon Jun 18, 2018 12:46 am

If you changed the default passwd, then your out of luck. Burn a new image to your SD card and start again.

Cheers.
Retired IT professional, C programmer and "beardie weirdie".
RPi interests: Developing an Infinite Improbability Drive
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Password Lost

Mon Jun 18, 2018 1:13 am

If you really want to save your OS having forgotten the password it can be pretty easy. All you need to do is edit the /etc/shadow file of the root partition of your SD card. The shadow file contains encrypted user passwords.

How are you going to edit the shadow file? Good question:

1) Put the SD card into a card reader of some other Linux machine. Perhaps another Pi. Now you can see and edit any and all files on the partitions of that SD card.

2) If you have a Windows machine with a card reader install the EXT file system driver from Paragon https://www.paragon-software.com/home/linuxfs-windows/. Put your SD card into the Windows card reader. Now you can see and edit any and all files on the partitions of that SD card.

3) If you are unlucky enough to only have a Mac available I have no idea. Perhaps somebody else can advise.

What are you going to put into the /etc/shadow file now that you can edit it? Good question:

1) Copy the encrypted password string, for the right username. A username you know the password of.

2) Copy an entire /etc/shadow file from a fresh Raspbian image thus resetting the password for pi back to it's default.

Note: If you have been adding and removing users from your original system before forgetting the password you may need to copy the /etc/passwd file over as well.
Memory in C++ is a leaky abstraction .

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: Password Lost

Mon Jun 18, 2018 1:25 am

It's probably easier to do the "init=/bin/bash" trick, than to try to edit files on the ext4 partition (unless, of course, you have other Linux systems available and are au courant on how to mount, edit, etc).

To the OP: I would suggest Googling for "init=/bin/bash" (or maybe /bin/sh - either or both may work) to get the details. But, basically, all you have to do is edit a file on the FAT32 partition (so no need for EXT4 access) and append " init=/bin/bash" to the end of cmdline.txt. Then when you boot, you'll get to a root shell (prompt is "#") and then you can reset your password. Again, details are available via Google; I won't go into them here.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Password Lost

Mon Jun 18, 2018 2:04 am

n67,

Hey, that's a good trick. Forgot about that one. Thanks.
Memory in C++ is a leaky abstraction .

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Password Lost

Mon Jun 18, 2018 8:56 am

Add

Code: Select all

systemd.unit=emergency.target
to the end of /boot/cmdline (which you can do on Windows for a plain Raspbian card or with the NOOBS cmdline recovery editor).

That forces a systemd system to boot to an emergency root shell.

If you replace NOOBS with PINN that includes a password reset function.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “General discussion”