What's new
VORON Design

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members!

Recovering RasPi Password

Rusty105

Well-known member
I am putting this here as I am using Klipper, but feel free to move if necessary.

I am trying to recover my password for the RasPi running Klipper for my Voron V0. I need to be able to SSH into the RasPi to do some software upgrades. It is a RasPi 4 running Bookworm. I have read where I can add a command line to a file then reboot the Raspi, but that needs a monitor and keyboard to make it work. The RasPi is headless. And since it is running Bookworm, there isn't a 'default' user , like "pi" as in older firmwares, I am not even 100% sure on the user name, ugh.

Is there any way to recover this without nuking the install and starting over?

thanks !!
Rusty
 
  • Power down and pull the SD card out from your Pi and put it into your computer. Open the file 'cmdline.txt' and add 'init=/bin/sh' to the end. This will cause the machine to boot to single user mode.
  • Put the SD card back in the Pi and boot.
  • When the prompt comes up, type 'su' to log in as root (no password needed).
  • Type "passwd pi" and then follow the prompts to enter a new password.
  • Shut the machine down, then pull the card again and put the cmdline.txt file back the way it was by removing the 'init=/bin/sh' bit.
Seen on StackExchange. You will need to change the username pi to whatever is the default user (go to the /home directory while the SD card is on your computer to see that, you may need to use a Linux desktop; alternatively, before issuing the passwd command go the the /home directory on the terminal, the command is cd /home, then do a ls command to show the directories on it - there should be only one, which is the default user).
 
Last edited:
Seen on StackExchange. You will need to change the username pi to whatever is the default user (go to the /home directory while the SD card is on your computer to see that, you may need to use a Linux desktop; alternatively, before issuing the passwd command go the the /home directory on the terminal, the command is cd /home, then do a ls command to show the directories on it - there should be only one, which is the default user).
Yeah, I have seen this method elsewhere...... But.... I would need to set up a keyboard and monitor for the Pi. I am thinking it might be the only way? I need to find a micro HDMI to HDMI cable/adapter first.....

Rusty

On edit: oh, wait. The StackExchange link shows something different. I might be able to do that. I do have another PC running Ubuntu. that might work....
 
Last edited:
Success !!!

It CAN be done without a monitor and keyboard, at lease not one connected to the Pi.

I have another computer running Ubuntu and that is what I used.

I pulled the micro SD card from the Pi and looked for the /etc/shadow file. opened it up and looked for the user I wanted to change the password for.

myuser:$5$_somelong_string:20046:0:99999:7:::

The password field starts with $5$ which is the id for using SHA-256 hash.

On my Ubuntu system I created a new user "tmpuser", and set a password, then looked in that system's /etc/shadow file, the password hash started with $6$.

I tried substituting this password hash for the one for my user on the RasPi, but no luck.

A little more reading and I found I could create a password hash using openssl, and specify what hash algorithm to use.

so on a command line I entered "openssl passwd -5 newpassword" and it spit out a password hash starting with $5$ . :) So I substituted this long string into the /etc/shadow file on the RasPi system, for the user I needed access into , and it worked !!!


@vinnycordeiro If you follow the StackExchange link you posted, there is another link to this method https://raspberrypi.stackexchange.com/questions/24770/change-reset-password-without-monitor-keyboard


Rusty
 
Success !!!

It CAN be done without a monitor and keyboard, at lease not one connected to the Pi.

I have another computer running Ubuntu and that is what I used.

I pulled the micro SD card from the Pi and looked for the /etc/shadow file. opened it up and looked for the user I wanted to change the password for.

myuser:$5$_somelong_string:20046:0:99999:7:::

The password field starts with $5$ which is the id for using SHA-256 hash.

On my Ubuntu system I created a new user "tmpuser", and set a password, then looked in that system's /etc/shadow file, the password hash started with $6$.

I tried substituting this password hash for the one for my user on the RasPi, but no luck.

A little more reading and I found I could create a password hash using openssl, and specify what hash algorithm to use.

so on a command line I entered "openssl passwd -5 newpassword" and it spit out a password hash starting with $5$ . :) So I substituted this long string into the /etc/shadow file on the RasPi system, for the user I needed access into , and it worked !!!


@vinnycordeiro If you follow the StackExchange link you posted, there is another link to this method https://raspberrypi.stackexchange.com/questions/24770/change-reset-password-without-monitor-keyboard


Rusty
Well, I didn't know your level of proficiency on Linux so I gave the easiest method to follow. Generating the hash externally to fool the system is definitely an advanced way to solve your problem, and I'm happy that you was able to solve it. 🙂 And one more way to do it to remember in the future, thanks!
 
Oh i am no Linux guru, I can thoroughly trash a production system, but I can follow directions fairly well.....

in reality , I know enough Linux to get by but still fumble on basic stuff.

Rusty
 
Top