(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Kerio Reseller
Printer Friendly Version

Lost root password (Linux)


Have you ever forgotten your root password? I have a very good memory. I remember most of my client's passwords (there are a few I forget regularly for no reason that I can understand, but I really do know most), I remember telephone numbers, and of course I know my own passwords. That last isn't as easy as it might sound, because I have quite a few different systems and each has its own password, but though I might use the wrong one now and then, I'll get it on the second or third try.

'Lost' photo by http:/ /www.flickr.com/photos/brainware3000/
Photo by brainware3000

If you just need to CHANGE root's password, and you are already logged in as root, just type "passwd" at a shell prompt.

Well, not this time. A while back I installed Fedora on a system here, and today I wanted to look at something and .. what was the root password? Hmm, not that.. how about? .. nope, well it must be.. darn!

Before we go to far with this, some systems use "sudo" and may have configured your ordinary user account to use it with your own password. Just on that chance, try typing:



sudo su -


at a shell prompt. If it asks for a password, just type in your usual password. If you get a "#" prompt, you are now logged in as root.

I wasn't using such a system and had no idea what the password was. Fortunately, it wasn't a boot password, so I did have access to the system. Without that, I would have had to dig up the CD's (who knows where they are) and do a recovery that way, or download something from Tom's Root and Boot Site. I had access to the Grub loader, so I had it easy.

If you've lost your root password, you might be able to recover it this way. However, some systems are protected with boot loader passwords that won't let you do that without THAT password. If the boot loader is password protected, you need to boot from other media - for newer systems, the install CD probably has the recovery tools for that ("linux rescue" for example).

But let's try it the easy way first. The first thing to try is to boot to single user mode. This MIGHT not work for you, because your system might be configured to still ask for a root password to get to single user mode. If that's the case, we'll use another trick that replaces init with /bin/bash.

First, try single user. If you don't see either a LILO or GRUB boot screen, try hitting CTRL-X to get one. If it's LILO, just type "linux single" and that should do it (assuming that "linux" is the lilo label). If GRUB, hit 'e", then select the "kernel" line, hit "e" again, and add " single" (or just " 1") to the end of the line. Press ENTER, and then "b" to boot. (More modern grub uses "a" to append to the boot line)

You should get a fairly normal looking boot sequence except that it terminates a little early at a bash prompt. If you get a "Give root password for system maintenance", this isn't going to work, so see the "init" version below.

If you do get the prompt, the / filesystem may not be mounted rw (although "mount" may say it is). Do



mount -o remount,rw /


If that doesn't work (it might not), just type "mount" to find out where "/" is mounted. Let's say it is on /dev/sda2. You'd then type:



mount -o remount,rw /dev/sda2


If you can do this, just type "passwd" once you are in and change it to whatever you like. Or just edit /etc/shadow to remove the password field: move to just beyond the first ":" and remove everything up to the next ":". With vi, that would be "/:" to move to the first ":", space bar once, then "d/:" and ENTER. You'll get a warning about changing a read-only file; that's normal. Before you do this, /etc/shadow might look like:



root:$1$8NFmV6tr$rT.INHxDBWn1VvU5gjGzi/:12209:0:99999:7:-1:-1:1074970543
bin:*:12187:0:99999:7:::
daemon:*:12187:0:99999:7:::
adm:*:12187:0:99999:7:::


and after, the first few lines should be:



root::12209:0:99999:7:-1:-1:1074970543
bin:*:12187:0:99999:7:::
daemon:*:12187:0:99999:7:::
adm:*:12187:0:99999:7:::


You'll need to force the write: with vi, ":wq!". (If that still doesn't work, you needed to do the -o remount,rw, see above).

Another trick is to add "init=/bin/bash" (LILO "linux init=/bin/bash" or add it to the Grub "kernel" line). This will dump you to a bash prompt much earlier than single user mode, and a lot less has been initialized, mounted, etc. You'll definitely need the "-o remount,rw" here. Also note that other filesystems aren't mounted at all, so you may need to mount them manually if you need them. Look in /etc/fstab for the device names.

Keep this in mind if you have a Linux machine in a publically accessible place : without more protection, it's not usually hard to recover a lost root password, which means it's just as easy for someone to CHANGE it, or access root without your knowlege.

Another way to do this is to remove the password from /etc/shadow. Just in case you screw up, I'd copy it somewhere safe first. You want to end up with the root line looking something like this:



# original line
root:$1$EYBTVZHP$QtjkCG768giXzPvW4HqB5/:12832:0:99999:7:::
# after editing
root::12832:0:99999:7:::


If you are having trouble with editing (you really do have to learn vi one of these days), you could just (after making a copy, of course) just



  echo  "root::12832:0:::::" > /mnt/etc/shadow 
or, if you were in single user mode
  echo  "root::12832:0:::::" > /etc/shadow 


and then fix things up when rebooted.

If using something like "linux rescue" or other boot media, if the recovery disk doesn't automatically mount your disk, you need to do it manually. This shouldn't be difficult unless you have an unusual disk controller. For example, a Compaq raid controller will probably be /dev/ida/c0d0. Find the partitions by using fdisk /dev/ida/c0d0 (just "p" and quit) and then mount what you need.

If all else fails, consider that you can pull this drive (or install another drive in this machine) and mount it from another running Linux. Then recover the root password as explained above.

See also
http://aplawrence.com/Bofcusm/861.html
http://aplawrence.com/Bofcusm/872.html
http://aplawrence.com/Bofcusm/873.html


Technorati tags:     

Comments /Linux/lostlinuxpassword.html
Thanks! you helped me a lot! Thanks, thanks, and... Thanks again!!!!!


You are king!


Helped me too. Thanks.

Same here. Thanks, man u saved me! :)

Quite usefull piece of information. Hellos from Finland 9.6.2004.

very helpful on my "learning linux - leaving windows" thank you.

Very nice way :)

Thanks! You saved the day.

Luckily this was 1st time I neeeded this, but this makes a mockary of linux security. Thx a million!

---July 21, 2004

No, there's no mockery: you CAN setup your system so that none of this would work.

--TonyLawrence





---August 3, 2004

Thanks! Saved me a headache :-)


---August 8, 2004

This helped me a lot. Thank you.


---August 14, 2004

Nice pease of information! Very helpfull!

---August 25, 2004

You have saved me! DCosta.

---September 27, 2004

reply to TonyLawrence: Yes, you can ... but still, there is no way to save your PC from hacker with physical access to it (reset CMOS by disconnecting battery, plug in own disk ...). Only way to protect data is encrypt them, which means typing password on each boot.

-- September 27, 2004

True, but even then, assuming physical possession and enough computing resources (and time, depending on the encryption), your data isn't safe.

Resources change, so you can't really depend that anything is safe.

I was simply noting that just because its this easy to break into a system without any extra controls (boot password, cmos password, encryption) it doesn't mean that it "makes a mockery of Linux Security".

Security, like everything else, is a matter of degree. A simple root password keeps your system safe from a very large number of people. As you add more impediments, you decrease the likelihood that the system can be compromised, but there is no absolute security, and even if you were 99.999 % secure today, changing technology might make that 80% tomorrow.

--TonyLawrence



---October 26, 2004


very nice! THX

-- butonic 2004-10-26 00:02:36.542

You ARE the man ! Saved a linux newbie from a lot of pain. Thanks!!

---October 26, 2004


---October 27, 2004

koolmen I got it. Perfect. You are good!

---December 1, 2004


Just perfect. The init-procedure worked for me, as the name for root was changed to iroot in passwd but not in the shadow!
THX!

---December 7, 2004

Yep! Works just like that! (I had to use the init procedure)! Saved my about 100 years time.. !THANKS
(SUSE 9)

Vassilis - Greece


---December 13, 2004

Worked great, helped me behind the maitenance root password by adding the shell command. I would never have thought of that! Thanks a million! (Suse 9.0)

Theo - The Netherlands

---December 25, 2004

Great and clear lesson, saves money and time, thanks <= r0bis, Latvia


---December 26, 2004

You Rock !! Nothing like a good Christmas day scare to refocus my efforts on getting around to documenting stuff.

---January 3, 2005

Grateful !!

---January 11, 2005

Seems to work with SuSE 9.2. Thanks so much!!


---January 17, 2005


Nicely documented. Thanks!
- Linux admin from Finland

---January 20, 2005

Seems pretty nice but doesn't work with Linux Mandrake 9.1. The "linux single" method asks for "root password for maintenance", and the other method makes kernel panic "attempted to kill init"...

---January 20, 2005

Hella cool. Thanks so much i installed Linux Mandrake 10.0 and then i must have typed root password wrong TWICE, so i did your trick with linux single and bam im in like flint. uber cool man!

---February 2, 2005



Thankyou , you saved me one days work !
Ivar, Oslo

---February 9, 2005

Merci, Just do it and "Voila"
Nicolas, Switzerland (SUSE 9.2)

Wed Feb 16 14:51:27 2005: Subject: thanks   anonymous
you just saved me, i have a presentation and the one that handles the computer quited, i didn't knew what to do thanks a lot



Sat Feb 26 16:23:56 2005: Subject: passwd recovery procedure worked for me   anonymous
Excellent site describing what you need to recover the passwd.


Took me more than 1 hour to reach this site, then 2 min to change my root passwd.
Thanks a lot!

Sat Feb 26 16:56:02 2005: Subject:   TonyLawrence
Just curious: why did it take you an hour to get here? This page is the number 1 hit for Google "lost root password" and is in the top ten for many other similar searches..



Tue Mar 8 21:23:50 2005: Subject:   anonymous
Thanks, excellent information. Helped me get into an old linux box that had been lying around for years and no one had the password.



-IT guy from Canada

Wed Mar 16 18:06:50 2005: Subject:   anonymous
Saved me a huge re-install. I knew I had done this before but I couldn't remember how and you were the only site I found with the COMPLETE information. Kudos.



Fri Mar 18 03:59:39 2005: Subject:   TyroneThanatos

good job man


you've slove my problem



Thu Apr 21 12:47:55 2005: Subject:   anonymous
thank you, thank you, thank YOU!





Tue Apr 26 04:13:10 2005: Subject: Root Password   Saturn
That way would work great, if you had the time and energy and patience to do it all.....Or you could just do this:



When the LILO: prompt appears (or boot: prompt if you inserted a boot disk), enter:

linux -s

OR

linux single

When the bash# prompt appears, enter:

passwd

This will then prompt you for a new root password, without asking for the old one.

Press Ctrl+D and start up Linux proper, then log in to the root account with your new password!

Tue Apr 26 10:06:36 2005: Subject:   TonyLawrence
Huh? Did you even read this?



The whole point is that the "simple" procedure sometimes isn't.. and the article says to do exactly what you say if you can do it that way!

Sheesh! :-)



Wed Apr 27 01:05:31 2005: Subject: Root Password   Saturn
Yes I read the article. And you was showing Linux Geru's (Supposibly) how to fix the problem of root password being lost. I just helped all those other people that just recently converted over from Windoze to *nix how to do the same thing in a lot less time and reading, and I almost bet, I didn't scare them off either!!!



Wed Apr 27 10:19:41 2005: Subject:   TonyLawrence
You have the wrong idea. First it's "guru" and I'm not one. See No Wizards Here



But more important than that is that you don't understand that your "simple" way isn't always going to work. If it did, that's all I would have written - why would I go on and on with "if that doesn't work, you need to" etc. if it would?



Sat Apr 30 01:16:44 2005: Subject: YOU ARE THE BEST   anonymous
Hey Man,



You saved my time...You are the best and Good Angels bless you for sharing your knowledge :))))


Angel

Mon May 23 10:41:17 2005: Subject:   anonymous
Thanks, thanks, thanks



Frans

Sat Oct 8 12:59:27 2005: Subject: Your the man!!   anonymous
That's so easy it's scary!








Sat Nov 26 19:19:57 2005: Subject:   anonymous
Sir,



you are great u made my day. Saved a lot of effort of us. May the Tux bless you with a looooooong n healthy life.

Mon Nov 28 17:52:01 2005: Subject: Thanks   Melvin
Dude, you help me alot.


you saved me from re installing the os
Thanks

Wed Nov 30 16:26:03 2005: Subject:   LeeGreen
I just reset a forgotten root password on Suse Linux 10. I needed to use the "init" method due to single user mode requiring root's password. However, I found that I did not have to mount the root filesystem since it was done automatically. I'm not sure that will be true in all cases under this version of the OS, but I would recommend using "df" to see if the filesystem is already mounted before assuming it's not.



Sun Dec 4 14:47:24 2005: Subject: really helpfull   anonymous
After sleepless weekend finaly a productive solution.


you really helped me since I'm working on my station since 2 month starting
with ZERO knowlage in Linux\Unix administration.

again and again 10x

Note - the "init=......." line is confusing, maybe you can notice that this line should be added without the commas.

Tue Feb 14 13:49:11 2006: Subject: an what about...   anonymous
... mac OS X.4? Any ideas?



Tue Feb 14 19:47:04 2006: Subject:   TonyLawrence
Sure. You need to boot single user mode.. see http://www.macosxhints.com/article.php?story=20001217230925152



Unfortunately the original article referred to there is apparently moved or gone.


If you previously bothered to set a Master Password (often ignored because they really don't explain it well, see http://aplawrence.com/foo-mac/master-password.html ), just mistype the login until it asks for the master.

Or, if you as Admin still have sudo rights, just do "sudo passwd root" in a terminal. It will ask for YOUR password first, and then you will be asked for a new root password.






Thu Feb 23 14:27:48 2006: Subject: Help   anonymous
Hi i m kiran , u r idea is to good... but one thing i dont get abot how i can get the root password ..suppose i m using Linux(any Version ) actually wht happen i have 2 account in that . one is root and other one is student . k so suppose i have to change something in System file so it must ask the password for ROOT so how i can know that. and one more thing suppose i want to Login in ROOT but i dont know the root password of that PC (Suppose this is NETWORK PC i m using telnet k and i want to know main server ROOt Password i can login with my ID and Password )but suppose i have to install new or change any thing in tht network so wht i can do 4 that....) can u help me on this problem ..............




form ur suggetion i can do that /bin/shadow but it cant show the password it can show some char like xhjagaz 2121addadzzaa xas like that so wht i ccan i do is there any METHOD to change that no into PASSWORD ..........

plz help me as soon as possible

bye
thanxk







Thu Feb 23 14:56:06 2006: Subject:   TonyLawrence
You can't *know* the password. Well, that's not entirely true, but there's no direct decryption method. If you have access to the shadow file, you can use programs like John the Ripper ( http://aplawrence.com/Words2005/2005_03_26.html) to try to match all possible passwords - that can take a long, long time (which is why cautious admins change passwords often)



Sun Feb 26 03:22:36 2006: Subject:   anonymous
Thanks! Saved me a lot of time!! )



Thu Mar 9 03:38:02 2006: Subject:   anonymous
(your comments go here)



i'm new to linux. I don't even know if I lost my password or not, because I don't know if the user that I have a password as root priveliges. No matter.
Just wanted to ask, does this site means afterall linux security is a mith?
It looks to easy to get someone else root password.

Thu Mar 9 11:13:11 2006: Subject:   TonyLawrence
No. With physical access to the machine, any OS is vulnerable. If you read all this carefully, you'd see that there is more you could do to secure your machine if you needed to.



Thu Mar 16 20:16:38 2006: Subject:   anonymous
Super! Thank you!



Mon Apr 10 18:00:06 2006: Subject: Yes!   anonymous
You saved me so much time reformatting!



Sun Apr 23 13:50:30 2006: Subject:   anonymous
Thanks very much for this - it was easy to find, easy to follow and the simple straightforward approach worked great with Fedora Core 5.








Mon May 22 22:41:18 2006: Subject:   anonymous
Chalk another one up - THANKS man!



Thu Aug 3 16:32:37 2006: Subject:   anonymous
Saved my butt too! Many thanks.



Thu Aug 10 15:49:01 2006: Subject:   zorrack
Really cool. Thanks a lot. No need to reinstall system :)



Tue Aug 29 20:54:48 2006: Subject: Works Great! Mandriva 2006 Official   anonymous
Thank you, thank you, just saved 4 hours here.



Fri Sep 1 15:12:09 2006: Subject:   anonymous
Thank you very much, on Suse 10.1 works fine the 2nd (init=/bin/bash)


solution; first solution asks, as you said, for root password.

Tue Sep 26 06:55:04 2006: Subject:   anonymous
It works!!!



Im using the Grub option.

Thanks. :)

Thu Oct 5 14:50:57 2006: Subject: good hint   anonymous
Yesterday I there was an successful attack on my gateway. The atacker changed the password so I had to rescue it. Thanx for this site.








Sun Oct 22 21:37:20 2006: Subject: need help - using ubuntu linux, lost root password   Chris
What do I need to do to get Tony's tips to work on Ubunutu Linux? Or maybe I missed something...??? I'm in a mess because without my root password, there are 189 updates in synaptic package manager that I can't get to because Ubuntu still thinks I am giving the wrong password. I hope someone can help me!!!



I can get to the Grub screen by hitting Esc, then 'e' to edit, 'e' again to edit kernel line (my system has 4 kernel lines to pick from, I just picked to first one, is that ok...?), then had to add ' single' because ' 1' didn't work the first time. Then hit 'b' to boot it. Then got the 'give root passwd for maint' message, so I tried the init method. It seemed to work fine. (' init=/bin/bash' instead of ' single'. then typed 'mount -o remount,rw /', and 'passwd', and successfully entered and re-entered new password.) However, when I reboot, the Ubunutu login screen still will not accept the new password for my login. Is it looking at an old copy of my old password, even though the unix or linux or whatever runs behind the GUI is looking at the new one?

Please try to use idiot-proof terms, I am new at Linux and will miss it if you skip over a step that you'd assume people would know.

Tue Nov 14 02:46:54 2006: Subject:   anonymous
Thank you, it was very helpfull :)



Thu Nov 16 10:30:49 2006: Subject:   anonymous
TY


i just installed a new version of linux on my box and i hmmm i must have entered a wrong passsword :P

Thu Nov 30 23:53:46 2006: Subject:   Mike
Yep. Works like charm. You are King.



We have a GRUB loader with FedoraCore Linux. Just type "a" at the loader screen, added "single" as one of the boot argument, continue with boot, chanced passwd file in single user mode. Works like charm.


Fri Dec 15 00:02:15 2006: Subject:   anonymous
great help. thank you... i misread how to enter grub, though, and somehow got to a regular grub shell, instead of grub append. so for anyone using fedora or redhat, press "a" at the boot loader menu (the colorized menu where you select which kernel to boot) and then you'll enter grub mode and you then just add the word "single" to the end of command and hit enter.



or just read this

http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/step-guide/s1-q-and-a-root-passwd.html

------------------------
Comments are closed for this page. If you have something very important to add, contact me by email.

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner





Views for this page
Today This Week This Month This Year  Overall
103691,64819,115 222,445

numly esn 55513-080107-472267-26
numly barcode

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:
       - Administration
       - Linux
       - Unix
       - Security




Related Posts

Using Sudo

Cracking passwords with John the Ripper

Master Password

Tough Passwords

Lost Root Password SCO Unix

Windows password cracking


Unix/Linux Consultants


http://www.schewanick.com SCO Unix, Solaris, Linx (various), PHP, MySQL, Apache, uniBasic, dL4, Perl, System Administration and more....


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


larryi@ccamedical.com SCO OS5, Debian Linux, RedHat Linux, MySQL, Apache, AJAX development using dXport/dL4/Unibasic, Windows Connectivity, Sharing Resouces, Automation, Shell Scripting


Your ad here - $24.00 yearly!

Twitter
  • May 13 17:19
    Too nice out - bailing..
  • May 13 14:07
    So today at the gym I only did rowing, walking and leg lunges. We'll see how my neck is tomorrow.




card_image






Coming Attractions

My Favorites

Change Congress

Related Posts