Resetting the Root Password

June 11th, 2009 by Dashamir Hoxha in

Your rating: None Average: 4 (15 votes)

The following methods can be used for resetting the root password if the root password is unknown.

If you use GRUB for booting, select the system to be booted, and add 1 to the end of the kernel boot command. If you're not presented with an edit “box” to add boot parameters, try using GRUB's edit command (the letter e). The 1 tells the kernel to boot to single-user mode.

The system now should boot to a root prompt. At this point, simply use the passwd command to change the root password.

Another option is to boot a rescue CD or an installation CD that lets you get to the command line. Once you're at a command prompt, mount the system's root directory if it's not already mounted:

$ mkdir /mnt/system
$ mount /dev/sda1 /mnt/system

Now, do a chroot and reset the password:

$ chroot /mnt/system
$ passwd

__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous's picture

Most motherboards have

On June 22nd, 2009 Anonymous (not verified) says:

Most motherboards have jumper of switch labeled "Clear CMOS". Just do it and the BIOS password is gone too.

Logick's picture

What about LILO?

On June 13th, 2009 Logick (not verified) says:

What are the steps to do this with LILO? I can Google it, but it would be nice to see that in this article for completeness. I liked the article BTW and I wish people had less time on their hands than to complain. I think if you lose the root password, the drawback of a simple reboot is insignificant in the grand scheme of things.

jf's picture

ignore this article

On June 11th, 2009 jf (not verified) says:

For Linux Journal I would hope that you wouldn't have such lame answers for such questions; but then again this type of stuff is exactly why I stopped paying you money years ago.

Just remember this: at the kernel command line: init=/bin/sh (you may need to also specify your root partition as being read-write, i.e. for /dev/sda1 init=/bin/sh root=/dev/sda1 rw)

Anonymous's picture

Rebooting is soooooo '80s

On June 11th, 2009 Anonymous (not verified) says:

Well, that was rather uncalled for...go get yourself some ice water. This tip is FREE...you didn't pay for the entire issue of the printed magazine....sheesh.

First of all, if you already have a access to a root shell prompt, remounting the root file system to run the passwd command is much quicker (and much more elegant). Suggesting a reboot of the entire machine just to get to a prompt that allows you to change the root password is just as bad of an idea as you claim this tip is.

FYI -- you can also replace the 'root' account information line in both the /etc/passwd and /etc/shadow files to either a known good-working one or no password at all. Just make sure the GID and UID remain at 0 otherwise, root is nothing better than a normal user...

Of course, all of these methods are much easier than trying to change the password on a Redmond-based OS's...unless you have a Linux boot disk, of course... ;).

Pawka's picture

How to avoid reseting by

On June 11th, 2009 Pawka (not verified) says:

How to avoid reseting by this way?

Anonymous's picture

how to avoid resetting..

On June 11th, 2009 Anonymous (not verified) says:

1. Set grub password.
2. In BIOS, prevent booting from CD and external media (USB, firewire)

Dan Fekete's picture

Physical access means game over...

On June 12th, 2009 Dan Fekete (not verified) says:

A bootloader and bios password are great deterrents... but don't rely on them to protect you. All one has to do is plug the hard drive into another system, mount and chroot as described above.

Steven Bakker's picture

... unless you encrypt your data

On June 12th, 2009 Steven Bakker (not verified) says:

All one has to do is plug the hard drive into another system ...

Indeed, once someone has physical access to your hardware all bets are basically off. The only feasible way of protecting your sensitive data is to use strong encryption and not store the encryption keys (or store them as far away from your data as possible).

See also http://www.linuxjournal.com/article/7743 which has tips for encrypting your (root) FS while booting off of a USB flash disk (so you only bring the two together when you boot).

Slacker 12.2's picture

It's

On June 11th, 2009 Slacker 12.2 (not verified) says:

It's simple.
Password-protect your bootloader(LILO or GRUB) and BIOS.
That way if anyone tries to boot your system to single-user mode he'll be immediately required to give the password.
Same goes to BIOS, if anyone tries to change your boot sequence to CD/DVD drive, they must give the BIOS password first in order to change the said boot sequence.

:)

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.







Read this issue