How to reset the Root password in Linux with GRUB and Single User Mode

AID: 1284
  • Status: Published

3960 points

This article assumes you are using the GRUB boot menu, and not LILO.  This has been tested on Fedora Core 8, 9 and 10, Ubuntu 8 and 9 series, OpenSUSE 10 and 11 series, and SLES 9.  It seems to work on all Kernels 2.4 and above.  It may work on lesser kernel versions, but the author has not tested this.

So you forgot your Linux Root account password eh?  Or maybe your company's previous IT manager left without leaving passwords behind to your Linux server? For many users, including IT professionals, this is a common occurrence.  Rest assured,  It's really easy to reset said password in just such a case.  This can be done by booting into single user mode (Runlevel 1).

*Note, if you use Fedora Core 10, you may need to hold down the "shift" key on the Fedora loading screen (The one with the 3 different colors of blue loading bar) until you see the GRUB menu.

Step 1)  If you have a graphical GRUB menu (Such as with openSUSE or Mandriva), you will want to hit the "esc" key at the boot menu.  This will prompt you with a message box saying you are leaving the graphical boot menu and starting text mode interface.  Hit OK.  Otherwise you may already be in the text mode interface.  In which case, skip to step 2.

Step 2) Once in text mode, highlight the default boot option (you want to reset the Root password for) and hit "e" to Edit the commands before booting.

Step 3) Highlight the line that starts with "kernel", press "e" again to edit this entry.

Step 4) At the end of the line, type the word "single". Mine looks something like this:
kernel /boot/vmlinuz-2.6.25.20-0 ... splash=silent showopts vga=0x314 single
                                    
1:

Select allOpen in new window


Hit "enter" to save, then hit "esc" to go back to the previous screen.  

Step 5) Still with kernel highlighted, Press "b" to boot.  Your system will boot without it's shiny graphical boot sequence (unless the vga=xxx option is set, in which case you will have a graphical boot).  

Step 6) If you use openSUSE, you will be presented with the following prompt:
Give root password for login:
                                    
1:

Select allOpen in new window


Type new password.

Other operating systems may put you right in the command prompt with root privileges.  In which case you will need to type the following to change the root password:
passwd
                                    
1:

Select allOpen in new window


type your new password and confirm it by typing it a second time if it asks you.

If you are using (K)Ubuntu 9.04 (Jaunty Jackalope and in some cases, earlier versions of Ubuntu) and you follow the above steps, you may find a known bug when presented with a text menu in which you may not be able to select anything, but instead can see all your key strokes as escape characters.  In such a case you may try this work around:

Instead of typing the word "single" as stated in step 4 above, type the following:
init=/bin/bash
                                    
1:

Select allOpen in new window

 
Using Kubuntu 9.04, mine would look like this:
kernel /boot/vmlinuz-2.6.28-11-generic ... part2 ro quite splash vga=0x314 init=/bin/bash
                                    
1:

Select allOpen in new window


Hit "enter" to save, "esc" to go back to the boot screen, and "b" to boot.  You will be presented with a prompt that looks like the following:
root@(none):/#
                                    
1:

Select allOpen in new window


Once at the prompt, type the following:
mount -t /proc
mount -o remount,rw /
passwd
                                    
1:
2:
3:

Select allOpen in new window


type the new password   (hit enter)
retype for confirmation  (hit enter)
You should now see a "password successfully changed" message.  
Reboot your machine and login.

You might ask, "Well, if it's that easy to reset Root's password, can't someone reset mine?"  The answer is YES!...Never give easy physical access to a data-sensitive system!  You can password protect the GRUB boot menu, and even the BIOS to prevent people from performing these steps, but that is not covered here.
Asked On
2009-08-05 at 17:45:40ID1284
Tags

Linux

,

Root

,

password

,

grub init 1

,

Single User Mode

Topic

Linux Administration

Views
3356

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Linux Admin Experts

  1. maeltar

    4,300

    0 points yesterday

    Profile
    Rank: Guru
  2. xterm

    4,000

    0 points yesterday

    Profile
    Rank: Sage
  3. noci

    2,800

    0 points yesterday

    Profile
    Rank: Genius
  4. duncan_roe

    2,800

    0 points yesterday

    Profile
    Rank: Genius
  5. pcsmitpra

    1,800

    0 points yesterday

    Profile
    Rank: Wizard
  6. testez

    1,800

    0 points yesterday

    Profile
    Rank: Guru
  7. Nopius

    1,470

    30 points yesterday

    Profile
    Rank: Genius
  8. abbright

    1,000

    0 points yesterday

    Profile
    Rank: Guru
  9. torakeshb

    1,000

    0 points yesterday

    Profile
    Rank: Master
  10. woolmilkporc

    800

    0 points yesterday

    Profile
    Rank: Genius
  11. dbauermann

    600

    0 points yesterday

    Profile
  12. wasimibm

    600

    0 points yesterday

    Profile
    Rank: Guru
  13. unassassinable

    420

    0 points yesterday

    Profile
    Rank: Guru
  14. Anton74

    390

    0 points yesterday

    Profile
    Rank: Guru
  15. kosarajudeepak

    340

    0 points yesterday

    Profile
    Rank: Wizard
  16. abolinhas

    320

    0 points yesterday

    Profile
    Rank: Guru
  17. viju2008

    300

    0 points yesterday

    Profile
    Rank: Master
  18. farzanj

    300

    0 points yesterday

    Profile
    Rank: Genius
  19. OP_Zaharin

    300

    0 points yesterday

    Profile
    Rank: Sage
  20. ahmedhamdy27

    290

    0 points yesterday

    Profile
  21. allen-davis

    280

    10 points yesterday

    Profile
    Rank: Master

Hall Of Fame