Tuesday, March 3, 2009

Reset the root password on a linux box

Intro
The following steps were used to successfully reset the root password of a "Fedora 10" machine. In general, can be applied to any linux machine.


  1. GRUBWhile booting, after the initial splash and POST screen of the bios, the control transfers to GRUB. If there is just one linux operating system installed, the GRUB screen is bypassed to the booting screen, in that case just keep on pressing or tapping the ESC Button until you see the GRUB Menu.
  2. Edit Choose the OS you want to boot into and press "e" to edit.
  3. Edit Find the line that corresponds to kernel, and again press "e". Add the following line to the end of the line.
    single init=/bin/bash

    Then press enter, and then "b" to boot the OS. After booting you will get a root shell.

  4. Mounting the filesystem in readwrite mode: Type in the following command to remount the filesystem in read write mode.
    mount -o remount,rw / 

  5. Not doing this step might give the following error when running passwd, passwd: Authentication token lock busy.
  6. passwd Next just use the passwd command, and give a new root password, Now that's simple.

  7. Reboot or init 5


That's really all I did.

OR from the root shell, you can also edit the /etc/shadow file to remove the password.
OR copy the /etc/shadow /etc/passwd file and use John-The-Ripper software to try cracking the password.

Stuck? Let me know...


.___.__ .__ __ .__ ___. __
__| _/|__| ____ |__|/ |______ | | ______\_ |__ | | __
/ __ | | |/ ___\| \ __\__ \ | | \____ \| __ \| |/ /
/ /_/ | | / /_/ > || | / __ \| |_| |_> > \_\ \ <
\____ | |__\___ /|__||__| (____ /____/ __/|___ /__|_ \
\/ /_____/ \/ |__| \/ \/

a8888b.
d888888b.
8P"YP"Y88
8|o||o|88
8' .88
8`._.' Y8.
d/ `8b.
dP . Y8b.
d8:' " `::88b
d8" 'Y88b
:8P ' :888
8a. : _a88P
._/"Yaa_: .| 88P|
jgs \ YP" `| 8P `.
a:f / \.___.d| .'
`--..__)8888P`._.'

24 comments:

Anonymous said...

it's not working for me
i get an error :
Warning can't access
exec of init() failed !!! : no such file or directory

maybe is the file system not mounted yet, as the kernel try to sort the init process (iam using a fedora distribution)

Arun Prabhakar said...

Hmmm, did u append the
"singe init=/bin/bash" ?

Anonymous said...

Am getting to the root shell but i cant use my keyborad it just freeze...
Have u exp. this type of error?

Arun Prabhakar said...

no it works fine here.
Is your keyboard working fine?

Anonymous said...

Thank you very much!

Anonymous said...

i cant boot into my root shell, i edited the line at my grub

Unknown said...

used it at college?? eh?? :D

Anonymous said...

@Arun Prabhakar "singe init=/bin/bash" ? this is wrong there is error in line
use this
single init=/bin/bash

Unknown said...

Thank you - this helped me out of a situation.

lerroux lopez said...

used this on ubuntu and centos with grub bootloader.

when you get on the shell prompt usually you cant edit the password and the files that contain the shadow unless you remount the fs and make it writeable:

mount -o remount,rw /

Anonymous said...

Thanks a lot! After getting the init=/bin/bash in the right place (it must be after single, not before,) I was getting stuck with Authentication ... busy until I saw your mount command and remembered that the root filesystem was still ro.

So this procedure worked great on Debian Lenny, too.

JoS said...

I unable to use my usb keyboard too, it is just frozen.

I noticed there is a message:
"hub 3-2:1.0:USB hub found"
"hub 3-2:1.0:3 ports detected"
"hub 3-2:1.0:new low speed USB device using uhci_hcd and address 3"
"hub 3-2:1.0:configuration #1 chosen from 1 choise"
"hub 3-2:1.0:new full speed USB device using uhci_hcd and address 3"

I will try attach my keyboard using PS2 connector tonight and see whether it works / not

JoS said...

Problem still exist, I tried "Usb to PS2 converter", my keyboard just frozen... :(

Lindylex said...

Thanks Arun Prabhak, it worked for me using Debian Squeeze. ~ Lindylex

Anonymous said...

works great for rhel 5.2 on dell 2950

James Kemp said...

This saved me hours of work. Just make sure to follow the steps. Append the init=/bin/bash on the END of the grub line. Once at the # prompt, make sure to remount the file system. The passwd command worked perfect!

Thanks again,
Jim

Anonymous said...

Hi,
None of the options are working for me, while I can't access the boot menu to add something on a line. There's a 'picture' where I can only select 'Linux' and press enter.
The somewhere found ctrl-x option to access boot menu isn't working.

This is a Slackware version 12.4 kde 3.5
using lilo somehow.

Are there any other possibilities besides using a bootdisk?

Thanks a lot,

parmeisan said...

Thank you!! I really didn't want to reformat that machine, since the only reason I was trying to log in was to save something from off of it.

Cheers!

Anonymous said...

I have a problem.
I open the grub and edit the ubuntu thing but then I get a window with no 'kernel'
starting with 'recordfail=1'
NO where do I see kernel or init=/bash/bin.

Im so lost :S

I need help. IF you need more info just lemme know

Anonymous said...

you are a beast thank you very much

Anonymous said...

You're a star, Got me out of a big Jam

Anonymous said...

You are a star, got me out of big jam

Anonymous said...

i want to install some software but unable to do so because i didn't have admin rights, can u help how can i do this on ubuntu..

jay shah said...

when i try to do
mount -o remount,rw /

it says
mount: could not open /proc/partitions, so UUID and LABEL conversion cannot be done.
mount: no such partition found.