Forgotten username and password to SSH into Pi

For a standard installation, the username is pi and the the password is raspberry.
If you had changed it, you even could not use restricted commands (like sudo) when you plug in a monitor and a mouse to the Pi.

My suggestion: Make a backup of the stored OctoPrint settings and data and play them back to a new OctoPi/OctoPrint installation.

3 Likes

Sounds like the way to go!

Thank you.

Or load the micro-SD card into a computer (PC, Mac) and edit the password file?

First make a full mackup on the computer before you edit the password file, if you're unsure about this. If you do the editing on a PC, beware of the Windows - Linux end of line difference, e.g. https://arstechnica.com/gadgets/2018/05/notepad-gets-a-major-upgrade-now-does-unix-line-endings/

1 Like

The password file (/etc/passwd) is located in the root directory, not the boot directory.
Windows PC can't read Linux formats...
In the end, he just has to read the user/password data, and the password is encrypted.
But as I said, not on a Windows PC.

And I'll add to this ^ that macOS also can't mount/read that second ext4 partition.

If you can get your hands on an Ubuntu Live CD or USB you can boot up your workstation so that you can edit files on that second partition.

But that suggestion to use Notepad for this since is a moot point. Use nano (command line) or gedit (GUI).

1 Like

Take the SD card out, put it in a card reader. Create a file octopi-password.txt on it, containing a new password as it's only line. Unmount, boot, login with the new password.

Put that in ages ago for cases liked this and for easier provisioning. Should hopefully still work.

19 Likes

This still works! Such a great idea, there was no way i was going to remember the password, and the init=/bin/sh method didn't work for me so this was perfect. Great foresight!

1 Like

Worked for me also. Without this I would have had to restore from one of the images but which one?

I had changed the pw for security and wrote it down and taped it to the pi (as I do with all my devices) but somehow it stopped working after a couple of years.

An important safeguard for all releases. Thanks from a sometimes user and Patreon-level supporter.

Where do I put this file?

For me, since I have macOS, I connect the microSD into the SD slot and it might look like this in a Terminal session:

cd /Volumes/boot
ls config.txt # Just to make sure I'm in the correct place
sudo echo "mypassword" > ./octopi-password.txt
1 Like

Thank you for your help.

Brilliant ! cheers for this :slight_smile:

Does this reset the username? I can't remember that but I do have acsess to the SD card
Any way to set the username and password via the card because on losing my login info I've also lost the login info for SSHing to the pi. So I can't do the reset

The default username is "pi" and I'm guessing that this octopi-password.txt trick will reset the password on that account (only). If you have created other usernames, you should be able to use "pi" to figure out what those names are.

This worked perfectly for me thanks

Just chiming in to say that this worked perfectly for me. I had to relocate my printer, and then of course had forgotten the password.
This fix is simply the best thing that's happened to me all month!

1 Like

Type in SSH pi@[network IP] and then enter the pw you specified in file when prompted. (I figured this out on my own, lol)

1 Like

works "today" (and before my last OS update - Octoprint was already: 0.15.1 / 1.6.1), but you should explain also that

  • the content is copied permanent into the passwd file?!??!
  • this file seems to be automatically deleted after first boot / first login / after copiing the content into passwd

Same claim is for the file wpa_supplicant.conf, but this is a raspberry topic and not a top security theme

Wow still works, what a life saver. That would have really sucked
{ Take the SD card out, put it in a card reader. Create a file octopi-password.txt on it, containing a new password as it's only line. Unmount, boot, login with the new password.

Put that in ages ago for cases liked this and for easier provisioning. Should hopefully still work.

1 Like

You absolute LEGEND. Thank you.