Lost Password - Help?!


14 posts
by dixonticonderoga » Wed Oct 24, 2012 12:21 am
So I'm an idiot and was changing my password and must have mistyped because I cant log in. I have my pi as a headless unit, and dont have a usb keyboard to plug into it. Is there any way to get my password? I've been logging into via SSH on my local network. Is there someway to read memory card on my windows computer to get and/or change my password?
Posts: 20
Joined: Fri Sep 28, 2012 6:05 pm
by Joe Schmoe » Wed Oct 24, 2012 12:40 am
I think the general method is to insert the card into a Windows machine, which will recognize the FAT partition and assign it a drive letter. Then edit the file "cmdline.txt" and append "init=/bin/sh" to the line.

Then boot the card on the Pi, and you will be taken directly to a shell prompt. From there, you can edit/fix the /etc/passwd and/or /etc/shadow files. Then edit cmdline.txt again, removing the "init=/bin/sh". Then reboot and all should be well.
Never answer the question you are asked. Rather, answer the question you wish you had been asked.

- Robert S. McNamara - quoted in "Fog of War" -
Posts: 2605
Joined: Sun Jan 15, 2012 1:11 pm
by jojopi » Wed Oct 24, 2012 1:00 am
Encrypted passwords are stored in the file /etc/shadow. But Windows will not be able to see this file unless you install non-standard software that understands the Linux ext4 filesystem. It would probably be easier and more reliable to temporarily boot a Linux LiveCD on the PC instead of installing ext4 software for Windows.

You cannot reset a password just by changing the boot files. (With the possible exception of the old debian squeeze armel image that had the file boot.rc.) You can only configure the card to boot in single user mode or similar. After that you would need a USB keyboard or a 3.3V UART adapter cable to actually log in.

It might be worth trying to guess what the typo in the password is first.
User avatar
Posts: 2036
Joined: Tue Oct 11, 2011 8:38 pm
by dixonticonderoga » Wed Oct 24, 2012 1:09 am
jojopi wrote:Encrypted passwords are stored in the file /etc/shadow. But Windows will not be able to see this file unless you install non-standard software that understands the Linux ext4 filesystem. It would probably be easier and more reliable to temporarily boot a Linux LiveCD on the PC instead of installing ext4 software for Windows.

You cannot reset a password just by changing the boot files. (With the possible exception of the old debian squeeze armel image that had the file boot.rc.) You can only configure the card to boot in single user mode or similar. After that you would need a USB keyboard or a 3.3V UART adapter cable to actually log in.

It might be worth trying to guess what the typo in the password is first.


I found a USB mouse that I can use to directly control the Pi. Is there anyway to get/change the password using only a mouse? Is there a virtual keyboard built in?
Posts: 20
Joined: Fri Sep 28, 2012 6:05 pm
by dixonticonderoga » Wed Oct 24, 2012 1:38 am
Joe Schmoe wrote:I think the general method is to insert the card into a Windows machine, which will recognize the FAT partition and assign it a drive letter. Then edit the file "cmdline.txt" and append "init=/bin/sh" to the line.

Then boot the card on the Pi, and you will be taken directly to a shell prompt. From there, you can edit/fix the /etc/passwd and/or /etc/shadow files. Then edit cmdline.txt again, removing the "init=/bin/sh". Then reboot and all should be well.


Wouldn't this method require me to have a usb keyboard plugged into the Pi?
Posts: 20
Joined: Fri Sep 28, 2012 6:05 pm
by jojopi » Wed Oct 24, 2012 1:56 am
dixonticonderoga wrote:I found a USB mouse that I can use to directly control the Pi. Is there anyway to get/change the password using only a mouse?
Probably not. Unless you had previously configured the image to boot straight into the GUI with no password, you would have to circumvent the normal boot sequence and use some kind of rescue mode. That will be text only, and the mouse is unlikely to do anything.
User avatar
Posts: 2036
Joined: Tue Oct 11, 2011 8:38 pm
by dixonticonderoga » Wed Oct 24, 2012 2:02 am
After finally finding a usb mouse, and doing tons of copying and pasting, I finally have my pi back under control, and have concluded I'm an idiot.
Posts: 20
Joined: Fri Sep 28, 2012 6:05 pm
by euxneks » Fri Oct 26, 2012 6:46 am
dixonticonderoga wrote:After finally finding a usb mouse, and doing tons of copying and pasting, I finally have my pi back under control, and have concluded I'm an idiot.


Well, I wouldn't call you an idiot, as recognizing a mistake is something an idiot wouldn't do :D
Posts: 26
Joined: Mon Sep 19, 2011 5:55 pm
by benjilev08 » Sun Feb 03, 2013 2:32 pm
I tried adding init=/bin/sh to the end of cmdline.txt as suggested but all that happens when I try and run it on the pi is that it runs about half of the normal start-up functions then just stops and does nothing. Is there something I am doing wrong?
Posts: 1
Joined: Sun Feb 03, 2013 2:25 pm
by Babzulbeg » Tue Mar 04, 2014 5:57 am
I cannot for the life of me find the file "cmdline.txt" anywhere on the SD card. Could someone direct me more specifically? Using Raspbian on a revision 2 Pi.
Posts: 4
Joined: Fri Dec 06, 2013 5:22 am
by DougieLawson » Tue Mar 04, 2014 11:44 am
Put the SDCard in your Windows machine and it should appear as F: (or some other new drive letter).
Open file explorer and you should be able to find F:\cmdline.txt
Hacker on ZX80 and Microtan65
Unemployed mainframe database specialist.
Linux hacker since 1995.
RPi owner since 2012.
Twitter: @DougieLawson

Gaffer tape is "The Force", it has a dark side and a light side and it holds the Universe together.
User avatar
Posts: 5777
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by Babzulbeg » Fri Mar 07, 2014 7:33 pm
Thanks for the reply. The question is now moot, as I have found the "missing" password on the post-it note where I wrote it down :roll: but I'm still curious about this procedure. The only item remotely resembling cmdline.txt is one called recovery.cmdline. (I DO have my system configured to display extensions.)

recovery.cmdline contains the following:
Code: Select all
reboot=q quiet vt.cur_default=1 coherent_pool=6M elevator=deadline

Is this what should be modified?
Posts: 4
Joined: Fri Dec 06, 2013 5:22 am
by DeeJay » Fri Mar 07, 2014 7:39 pm
Babzulbeg wrote:The only item remotely resembling cmdline.txt is one called recovery.cmdline. (I DO have my system configured to display extensions.)

recovery.cmdline contains the following:
Code: Select all
reboot=q quiet vt.cur_default=1 coherent_pool=6M elevator=deadline

Is this what should be modified?


In that case you are running the NOOBS installer. All the previous contributions to this thread date from prior to the release of NOOBS, and are not directly relevant.

The NOOBS recovery console has its own editor for the configuration files for the currently active Operating System.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
User avatar
Posts: 2033
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK
by Joe Schmoe » Fri Mar 07, 2014 7:43 pm
benjilev08 wrote:I tried adding init=/bin/sh to the end of cmdline.txt as suggested but all that happens when I try and run it on the pi is that it runs about half of the normal start-up functions then just stops and does nothing.


This is standard - happens all the time and you have done nothing wrong.

Just hit <enter> once it stops and you'll get the prompt.

What happens is that the shell has initialized and emitted the prompt before all the "booting up crap" has been displayed. If you look carefully about mid-screen, you'll see a little "#" symbol - that is the prompt. Hitting <enter> at this point just causes it to re-send the prompt.

Re: The issue of NOOBS (raised by another poster down-thread)

The standard advice about finding and editing the cmdline.txt file is given on the assumption that you are running one of the "raw" images - since those were the only images we had when all this advice was first thought up and given. The details change now that we have NOOBS.

Basically, in NOOBS, you might be able to fix things by monkeying with "recovery.cmdline", but it might not work as expected. To do it right, you need to find the partition that will eventually be /boot once your chosen OS has booted. This might be something like /dev/mmcblk0p10 or something like that. The kicker, though, is that even though this will be a FAT partition, it probably won't be visible under Windows - because Windows is, well, Windows…

So, you may end up needing a Linux system in order to mount the partition and edit the file.
Never answer the question you are asked. Rather, answer the question you wish you had been asked.

- Robert S. McNamara - quoted in "Fog of War" -
Posts: 2605
Joined: Sun Jan 15, 2012 1:11 pm