Recovering a Raspberry Pi Password on an M1 Mac

I would never accidentally change my Raspberry Pi's account password before clicking "save" in my password manager, therefore locking myself out. But let's say, hypothetically, that I did. How would I get back into my account?

The process would look like:

  • Power off the Raspberry Pi.
  • Eject its SD card.
  • Put the SD card in my M1 Mac.
  • Magically replace the Pi's /etc/shadow file with the previous /etc/shadow- version, undoing the password change.
  • Put the SD card back in my Pi.
  • Power up, log in, and pat myself on the back.

Hypothetically, that magic bit could be a pain in the neck.

False start #1: ext4fuse

The relevant part of the Pi's SD card is formatted with the ext4 filesystem. macOS doesn't natively support ext4, and I'd need to install software so that I could access and edit the files on the card.

First, I'd install the open source ext4fuse program and navigate to the Pi's /etc directory. Only then would I realize that ext4fuse is a read-only filesystem and doesn't support writing at all.

False start #2: extFS for Mac

If the open source option didn't work, I'd try the paid extFS for Mac filesystem and use its trial offer to do the work.

After installation, I'd discover that something in the way that the Pi formats its SD card prevents extFS from mounting it.

False start #3: run Debian in a VirtualBox VM

I bet by then I'd give up on mounting the filesystem inside macOS, and accept that it'd be easier to do the work inside a Linux VM. I'd likely hold my nose and download Oracle's VirtualBox. Bummer that it doesn't work well on M1 Macs yet, which I'd learn would cause the Debian installer to reboot every couple of minutes.

Success at last: Parallels Desktop

After trying and ruling out everything else, I'd probably try the trial version of Parallels Desktop. I'd use it to install Debian, then go to the Devices > USB & Bluetooth > Apple SDXC Reader Media (disk6) menu to mount the Pi's SD card inside the VM. Then I'd open the VM's Terminal app and run:

cd /media/parallels/root/etc
sudo mv shadow shadow.bak
sudo cp shadow- shadow

Finally, I'd go into the VM's Files app and unmount the "boot", "root", and "SETTINGS" disks.

Crossing my fingers

After all that, I'd pop the card out, stick it back in the Raspberry Pi, boot it, log in via SSH, and run sudo -s. At the password prompt, I'd type my original password (as stored in my password manager), then exhale in relief as I was once again able to log in.

That is, if I were to lock myself out in the first place. Which I never would. Because I'm a professional.

Related Posts