Find text history entered into ubuntu command line (get lost password)
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 :)
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.
-
Write a bash script to save it. You can, for example,
tee
everything to STDIN and a file of your choosing. -
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
- Power down and pull the SD card out from your Pi and put it into your computer.
- Open the file 'cmdline. ...
- 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.
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.