Score:2

Recover lost password from Raspberry Pi 4B

cn flag

I have an RPi that I have forgotten the password to. I have history on the ubuntu command line on my PC of ssh logins and I was hoping there would be a way to get text history entered into to try to find my password. If not is there a way to recover an RPi password? I am running Ubuntu Server (not Raspbian) and was unable to access GRUB.

Earlier I was using the history command but that only shows the ssh commands and not the details entered in.

Any help would be massively appreciated!

EDIT - Some solutions don't work because they are for the Raspberry Pi 3B and below and I have a Raspberry Pi 4B

EDIT - I have found a solution thanks to a friend of mine, I will put an answer below. Thanks to everyone who helped me :)

ChanganAuto avatar
us flag
You can list commands, not passwords.
sudodus avatar
jp flag
If your file system is *not* encrypted, you can create a new password according to the answers in [this link](https://askubuntu.com/questions/24006/how-do-i-reset-a-lost-administrative-password). I suggest that you try according to the answer by Jorge Castro.
sudodus avatar
jp flag
Does this answer your question? [How do I reset a lost administrative password?](https://askubuntu.com/questions/24006/how-do-i-reset-a-lost-administrative-password)
Bobcat33 avatar
cn flag
No, all of these require access to the GRUB menu which I am unable to access on my RPi
sudodus avatar
jp flag
In a PC you get to the grub menu if you press the left shift key during boot. Maybe it works in RPi too.
Bobcat33 avatar
cn flag
@sudodus It unfortunately doesn't, I spent about 10 minutes trying that this morning
Bobcat33 avatar
cn flag
@NateT I know but I was hoping that there would be a simple solution...
sudodus avatar
jp flag
Can you boot from an Ubuntu live USB drive, or is it [still] necessary to boot RPi from the SD card? Have you access to a PC computer, where you can connect your SD card with the system?
hr flag
Unless you used something like `sshpass -p mypassword` or `echo mypassword | sshpass` then you didn't enter your password into the ubuntu command line, it would have been read directly by the `ssh` client
Bobcat33 avatar
cn flag
@NateT oof! Thanks for your answer, I just came across a similar answer [here](https://howtoraspberrypi.com/recover-password-raspberry-pi/) - glad it can be resolved!
sudodus avatar
jp flag
Can you read the files in the SD card, when connected to the PC computer? In that case the fastest solution might be to make **backup copies of your personal files** (documents, pictures etc), and then make a **fresh installation of Ubuntu** into the card, or get a new (maybe bigger) card and install Ubuntu into the new card.
Bobcat33 avatar
cn flag
@sudodus the previous solution isn't working so I will probably try that, thanks :)
Nate T avatar
it flag
Wait WHAT ABOUT .BASHRC?! IT SHOULD BE ON THE MEMORY CARD! iT AUTORUNS SH!!!!
Nate T avatar
it flag
Just a shot in the dark for posterity: You don't have postgres installed do you? If so, you can ssh as postgres user.
Score:2
it flag

You can show a lot of it with:

cat .bash_history

or just

history

However, once the buffer is full, only some of them will be written. The rest will be lost. You can deal with this in at least 2 ways.

  1. Write a bash script to save it. You can, for example, tee everything to STDIN and a file of your choosing.

  2. Edit ~/.bashrc -- There is a line in this file that sets a cap on the count and another for file size.

As for login credentials, no. Otherwise, users could just look at each other's passwords.

I am not sure where the credentials are stored, but I would almost guarantee that they are encrypted.

EDIT From here

  1. Power down and pull the SD card out from your Pi and put it into your computer.
  2. Open the file 'cmdline. ...
  3. Put the SD card back in the Pi and boot.
  4. When the prompt comes up, type 'su' to log in as root (no password needed).
  5. Type "passwd pi" and then follow the prompts to enter a new password.
Bobcat33 avatar
cn flag
Thanks! I also came across a very similar answer [here](https://howtoraspberrypi.com/recover-password-raspberry-pi/)!
Bobcat33 avatar
cn flag
Actually it seems these answers have not worked as I am using a Raspberry Pi 4B and the software has been updated since then...
sudodus avatar
jp flag
Nice try Nate :-) I was hoping too, that the method you suggest in the edit would work. Anyway I upvoted your answer - I think the method will work for users of older versions of RPi.
Nate T avatar
it flag
Thank you. What about using sudo? Is remote root access enabled? There is another maybe option but its too much work for a maybe. It involves loading a bridged VM/hypervisor or container/daemon onto the memory card with a bridge. Then you should be able to wake it up via network.If it is configured via files, rebooting will connect it without user. The problem would then be 'getting out of the box.'
Nate T avatar
it flag
Kind of like you can tunnel in, you just can't dig up. In other words I have no idea...
Score:2
cn flag

To solve this issue I took the SD card out of the pi and opened it in another linux machine.

In the terminal I used the command below to remove the "x" from the root user line

sudo nano /mnt/sdcard/etc/passwd

(You may need to mount the SD card or USB stick reading the SD card)

Then I was able to put the SD card back into the pi and log in to the root user without typing a password.

Finally I could create a new password using the passwd command.

Score:0
cy flag
crh

As this seems unresolved for newer versions of Ubuntu: Take the SD card from the Pi and insert it into a computer that can read/write the ext4 filesystem. Mount the second partition (e.g. /dev/sdb2) and edit the <mountpoint>/etc/shadow file.

If you need a password to insert, you can use

mkpasswd --method=SHA-512 --stdin

to generate one. Erase the old one, add the new one. Put card back into Pi. Boot up as normal, the password you created with mkpasswd should now be set.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.