Reset OS password

Drop in for a chat and a cup of tea

39 posts   Page 1 of 2   1, 2
by paulmckinnie » Fri Oct 19, 2012 1:59 am
Hi all,
I'm new to the raspberrypi and to linux both. I setup the os yesterday complete with password and wrote the information down. Today when I tried to log into the os, I could not get it to work. How can I get the password changed so I can use the computer?

Posts: 4
Joined: Fri Oct 19, 2012 1:17 am
by billb » Fri Oct 19, 2012 3:21 am
I'm sure one of the experts will have a better way to do this, but ...

If you have access to a computer with an SD card reader you can edit the cmdline.txt file and add this to the end of the line:

Code: Select all

(it would probably be a good idea to save a backup copy of the cmdline.txt file first)

Then put the SD card back in the Pi and boot. You should arrive at a shell prompt # (you may need to press Enter for it to show up when it's done booting).

To change the password for the default user ("pi"):

Code: Select all
passwd pi

You will be prompted to enter the new password twice.

Then turn off the pi, move the SD card back over to the computer and remove the init=/bin/sh parameter from the cmdline.txt file (or restore from backup).

reference: viewtopic.php?p=109612#p109612
User avatar
Posts: 177
Joined: Wed Sep 19, 2012 10:27 pm
by paulmckinnie » Fri Oct 19, 2012 4:34 am
Thanks for the replays.. I am totally out of my knowledge lever here. I tried to find the line to change on my pc with no luck.. would I be able to change that line if I tried to find it on a Mac? My son has a mac but he wouldn't be around til Saturday.
Posts: 4
Joined: Fri Oct 19, 2012 1:17 am
by billb » Fri Oct 19, 2012 5:39 am
Assuming you're using Raspbian wheezy, there's only one line in the cmdline.txt file. When you insert the SD card in a Windows machine a window normally pops up and asks if you want to open the folder to view the files. In the resultant window you should see a text (.txt) file named cmdline or cmdline.txt ... you can right-click on that and select Open with -> Notepad.

It normally looks like this:

Code: Select all
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

And you'd change it to this (the only change being the addition of init=/bin/sh at the end):

Code: Select all
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait init=/bin/sh

(your browser is most likely wrapping the text to multiple lines, but it's really just one line)

You should be able to edit the text file on a PC or Mac. When you're done resetting your password you just change it back.
User avatar
Posts: 177
Joined: Wed Sep 19, 2012 10:27 pm
by paulmckinnie » Fri Oct 19, 2012 8:51 pm
Ok I did find the command lone and made the addition at the end. Then booted the system up and now I am back at the raspberry login. what should I type in there to start the password change?
Posts: 4
Joined: Fri Oct 19, 2012 1:17 am
by billb » Fri Oct 19, 2012 8:59 pm
If you're at the # prompt, just:

Code: Select all
passwd pi
User avatar
Posts: 177
Joined: Wed Sep 19, 2012 10:27 pm
by paulmckinnie » Sat Oct 20, 2012 4:04 am
Hi Bill, Thanks for your help. I have changed the command line but the bootup goes all the way to login name and password not the # prompt. I have checked the command line and everything is the same as the one on the reply including the int addition.
the linux I am using is debian that is on the 4gig MC.

Paul :?:
Posts: 4
Joined: Fri Oct 19, 2012 1:17 am
by billb » Sat Oct 20, 2012 4:29 am
Hmm... not sure why that isn't working, then. I tested it on my RPi running the Raspbian wheezy 09-18-12 and was able to change my password that way (pretending I forgot it).

I'm assuming you got the card with Debian pre-installed along with your RasPi ... ? At this point it might be easier just to download the latest Raspbian image (here) and overwrite your SD card (you would lose anything previously saved to it, though). It's a fairly easy process -- you just want to make sure you select the correct drive letter when using Win32DiskImager. I've been using the 0.5 release on Windows 7.
User avatar
Posts: 177
Joined: Wed Sep 19, 2012 10:27 pm
by steve-pie » Wed Jan 02, 2013 8:26 pm
I am experiencing exactly the same problem however I downloaded a new version of the OS onto a different card and this one wont boot at all. Do you need to do anything to make the card active?
Posts: 1
Joined: Wed Jan 02, 2013 8:22 pm
by RoboAndy » Sun Apr 07, 2013 12:06 pm
I had a similar problem that I forgot my password. At first the solution mentioned to edit the file and add 'init=/bin/sh' did not work for me either. I think this was because Shell (which is what i think the line init=/bin/sh is initiating) didnt understand my wireless logitech keyboard, I couldnt type anything. I switched to a wired usb keyboard and the PI booted so I could reset the password.

Hope this post helps.

Posts: 1
Joined: Sun Apr 07, 2013 12:00 pm
by kalo » Sat Apr 27, 2013 9:51 pm
I had the same problem. I wasn't seeing the shell prompt, but instead the pi gave me the login prompt There is a difference in the way windows and Linux represent a new line and the text needs to be exactly one line apparently, so when working on windows you must put the cursor at the end of
Code: Select all
before the empty space. Then hit space and enter
Code: Select all
. That fixed my problem and let me see the shell prompt - #.
Posts: 1
Joined: Sat Apr 27, 2013 9:41 pm
by knick007 » Sat Aug 24, 2013 8:05 am
Sorry for posting on a older forum but I have forgotten my password and I am trying to get into bash on my pi.

I have eddied the cmdline.txt file and I keep getting the same thing - the raspberry pi login prompt.

Any ideas anyone? I know it could just be where I put the init/bin/sh
Posts: 16
Joined: Tue Jan 22, 2013 7:41 am
by migueld » Mon Sep 30, 2013 6:40 pm
Hi. I did this cmdline.txt fix, but got sent right back to the login line when I powered up. I did not get a # prompt. However, I was able to login with "pi" as the user and "raspberry" as the password. Once in, I easily reset my password. Hope this helps.
Posts: 1
Joined: Tue Feb 26, 2013 5:55 am
by vng3333 » Thu Oct 24, 2013 5:44 am
In my case, I didn't forget the password. I actually stumbled upon a tricky raspi-config design bug. More details on what it is and how to work around it here: ... onfig.html
Posts: 3
Joined: Fri Oct 26, 2012 2:45 am
by tiberiu_szm » Mon Dec 16, 2013 9:48 pm
One of the easiest methods, provided you have another working Linux distro (that you can log into) is to simply copy the password hash from the user you've just logged in and overwrite the one from your rPI. That's located in /etc/shadow in one of the automatically mounted partitions of the SD card. And voila, you can login into your rPI with the same password you've logged in the other linux distro. Enjoy!
Posts: 1
Joined: Mon Dec 16, 2013 9:38 pm
by williamhbell » Fri Dec 27, 2013 8:56 am
If your system is setup to login automatically, you can

Code: Select all
sudo passwd pi

and put a new password, without having to give the previous one.


User avatar
Posts: 290
Joined: Mon Dec 26, 2011 5:13 pm
by r4rounak » Sun Dec 29, 2013 4:23 pm
I tried adding init=/bin/sh

Iam getting an error :
/bin/sh : cant access tty job control turned off

What should I do ?
Posts: 2
Joined: Sun Dec 29, 2013 4:19 pm
by rpdom » Sun Dec 29, 2013 4:48 pm
Press the Enter key and see if you get a "#" prompt.
User avatar
Posts: 10822
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK
by r4rounak » Tue Dec 31, 2013 6:12 am
rpdom wrote:Press the Enter key and see if you get a "#" prompt.

No I am not getting a # prompt. In fact the keyboard is not working at all. I can see a cursor, but when I press Enter nothing happens. When I press Ctrl+Alt+Del reboot doesnt happen.
Posts: 2
Joined: Sun Dec 29, 2013 4:19 pm
by buteman » Thu Jan 09, 2014 8:45 am
When I edited config.txt my Pi would not boot, it hung part way through the boot process.
Here's how I got it sorted.
I put the SD card in my Linux laptop and edited /etc/shadow.
I already had an entry for myself in it so I did two things.
First I slightly changed my name in the entry.
Second I then copied and pasted the line from my laptop to the end.
After this I edited /etc/sudoers and added an entry for myself with the same permissions as the pi user.
I put the card back in my pi and rebooted it, logged in as myself and did:
sudo passwd pi, changed the password for pi and rebooted.
I logged in as pi and undid the changes I had made to /etc/shadow and /etc/sudoers.
Back to normal now.
If you don't have an entry for yourself in /etc/shadow then you just miss out that part and it will still work.
There are few rewards greater than accomplishing a difficult task. Just because something doesn't cost money doesn't mean there is no cost. Every success makes the next one easier. Of course that takes determination and patience.
Posts: 96
Joined: Tue Jul 03, 2012 9:06 am
Location: Barrow upon Humber
by Alex63 » Thu Jan 23, 2014 9:20 am
If, like me, you screwed up your Raspberry Pi and need to get into single-user mode, you probably found your way here via Google. I put a bad file in my /etc/sudoers.d directory, and couldn't use the sudo command any more. I was hooped! I tried the instructions above, but like other people (see above) I found that my pi would not boot into single user mode. If I used the "init=/bin/sh" parameter it went through the normal process up to the point where the keyboard and trackball were detected, and then froze (you may see a console message from /bin/sh about no job control).

Maybe the suggested solution worked with an earlier version of the software, or maybe it works with different keyboards, but it didn't work for me. If you are having the same problem, don't worry, there is a solution:

  • Power up your pi and boot into the NOOBS recovery environment by holding down the SHIFT key when you see the Raspberry Pi logo and the instruction to press SHIFT.
  • Highlight the installed OS (I was using Raspbian). The Edit Config button should now be enabled.
  • Click the Edit Config button, and select the tab for cmdline.txt.
  • At the end of the line (right after "rootwait"), add a space (" ") and the digit "1". This will tell the kernel to boot to runlevel 1 (single user mode). Although it looks like there are multiple lines in cmdline.txt, there is really only one line that is folded. Don't put the "1" on a new line!
  • Click the OK button, then click the Exit button to leave Recovery environment.
  • Your pi should now boot into single-user mode. You will see a prompt like: root@hostname ~ #. Make the changes you need to fix your problem. Be careful, because you are now the root user!
  • Use the "exit" command to leave single-user mode, and continue the boot process to multi-user mode.
  • If everything is working correctly again, you should edit /boot/cmdline.txt to remove the "1" that you added to the end of the line. If you don't, the next time you boot your pi it will return to single user mode.

I hope this helps someone!
Posts: 1
Joined: Thu Jan 23, 2014 8:50 am
by Justinhultz » Sat Sep 27, 2014 5:11 am
I got it to reset my password but I must have a bad username. How do we reset the username?
Posts: 1
Joined: Sat Sep 27, 2014 5:09 am
by DougieLawson » Sat Sep 27, 2014 9:25 am
Justinhultz wrote:I got it to reset my password but I must have a bad username. How do we reset the username?

useradd & userdel

Add a new id, delete the "bad" one.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.
User avatar
Posts: 28101
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by rpaugusto » Tue Dec 16, 2014 10:59 pm
For those that reported that the 'init=/bin/sh' method didn't work, 2 scenarios:


Like described by Alex63, it freezes mid-boot. Just press Enter, the root prompt will show. Then follow the rest of the instructions.


It boots to normal prompt. It happened to me too. Simply explained, the text you entered is in the next line and it shouldn't. That's because I used Windows' Notepad and Notepad doesn't interpret the End-Of-Line (EOL) character of the cmdline.txt correctly and shows everything in one line (text files generated in Windows systems use the CR+LF character sequence, those generated in UNIX-like systems use only the LF character).

To edit correctly, either do it on another UNIX-like system (eg, other Linux system) or use Notepad++ ( in Windows to edit, it will interpret correctly the text file and maintain the correct structure. After that it might happen the 1st scenario when you boot but it's easy then.

Hope this helps.

Posts: 1
Joined: Tue Dec 16, 2014 10:42 pm
Location: Braga, Portugal
by fraser.the.gunner » Mon Apr 27, 2015 5:18 pm
If like me you didn't really have anything saved all you need to do is completely reboot your system.
Posts: 1
Joined: Mon Apr 27, 2015 4:47 pm