I need to reset my password. I have followed these steps:

How do I reset a lost administrative password?

However, then I go to "root" or "netroot" recovery options, it tells me:

Give root password for maintenance (or type Control-D to continue)

Clearly, I do not know the root password. If I type CTRL+D, I return to the list of options. From this page I read:

Under chapter 'The Other Way':

4. Highlight the line that begins kernel and press 'e' to edit`

But in the grub configuration file I have no line that starts with kernel. Only:

setparams 'Ubuntu...'
recordfail
set gxfpayload...
insmod part_msdos
insmod ext2
set root=...
search --no-floppy...
linux /boot/vmlinuz-2.6.38...
initrd /boot/initrd.img-2.6....

Those are all lines in my GRUB. Which line should I edit? Or is there another way to reset my password?

  • 1
    Please see this answer: askubuntu.com/questions/24006/… – cprofitt Apr 13 '12 at 14:50
  • That does not work, it tells me to type the password... – please delete me Apr 13 '12 at 14:51
  • It means this line linux /boot/vmlinuz-2.6.38... Did you set a root password? – 23 93 26 35 19 57 3 89 Apr 13 '12 at 15:04
  • @forestpiskie I tried that line but it then freezes... just nothing happens. Not sure about root password being set; this is not my own computer (assisting a friend). – please delete me Apr 13 '12 at 15:16
  • Are you trying to hack yourself into a computer? Because if you don't know the root password and the first user password, it is a bit smelly... – gajdipajti Apr 13 '12 at 20:23
up vote 28 down vote accepted

Since you cannot access recovery mode, you'll have to change the password by accessing your installed Ubuntu system from a live CD/DVD or live USB system. What follows is a detailed walkthrough on how to do that.

This is easiest if you can already use the Ubuntu system (even without administrative access). But it's not too much harder if you can't.

  • In my experience, most Ubuntu users who end up locked out of their own systems have automatic login enabled, which is how they forget their passwords (because they don't have to type them in to log in). This may or may not be the case in your situation, but I have presented how to do this if you can use the installed Ubuntu system first because I think that will help the most people who read this post.

If You Can Use the Installed Ubuntu System, Even As a Non-Administrative User

  1. If you don't already have one, write an Ubuntu live USB flash drive (on Ubuntu, Windows, or Mac OS X), or burn an Ubuntu live CD/DVD (on Ubuntu, Windows, or Mac OS X).

  2. If you know the device name of the partition that contains your Ubuntu system's root filesystem, feel free to skip to step 5.

  3. In your Ubuntu system (not the live CD/DVD/USB system), run this command in the Terminal:

    mount | grep ' on / '
    

    You should include the spaces before on and after /.

  4. That command produces something like /dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0) as the output. The text before on (not including the space) is the device name of the partition that contains your Ubuntu system's root filesystem. Remember it (or write it down).

  5. Boot the computer from the live CD/DVD/USB and select Try Ubuntu without installing (not Install Ubuntu).

  6. Open up a Terminal window (Ctrl+Alt+T).

  7. Run this command:

    sudo mount /dev/sda1 /mnt

    Replace /dev/sda1 with the device name of the partition containing your Ubuntu system's root filesystem, if different.

    If you get an error message about how a device or partition does not exist or about an "unknown filesystem type," then you probably used the wrong device name or partition number. As explained above, your system's root partition might not be /dev/sda1.

  8. Run this command:

    sudo chroot /mnt
    

    For the purposes of being able to reset a password, or being able to change what groups users are members of, that's all you need to do to chroot in. In particular, you do not also need to mount other filesystems like /dev, /dev/pts, /sys, and /proc. More sophisticated chrooting procedures, which allow you to fully use the system you are chrooted into--for example, to update and install software inside it--do require that, as well as additional steps after entering the chroot, but this does not.

    If you run sudo chroot /mnt and you see this message, it almost always means that you mounted the wrong partition to /mnt--remember, it will not actually be /dev/sda1 on all systems--though it would also happen if you deleted /bin/bash:

    chroot: failed to run command ‘/bin/bash’: No such file or directory
    

    If that does happen, then you can unmount it with sudo umount /mnt and then proceed to mount the correct partition.

  9. Perform one of these tasks, to obtain/restore access to the install Ubuntu system.

    • If you want to reset a user's password:

      passwd username

      Replace username with your username. (This is the username on the system installed on the hard drive, and not "ubuntu" which is the username of the default user on the Ubuntu Desktop Install CD.)

      Enter the password you want for that user.

      • If you don't know your username, you can get a list of users on the system by running:

        ls /home
        

        This works because /home contains all the users' home directories, and the name of a user's home directory is the same as the name of the user.

    • Alternatively, if you want to set/reset the root password:

      Since you're in a root shell, you can use the passwd command with no arguments to reset root's password:

      passwd
      

      But please see this page, which explains why having the root account enabled is not recommended in Ubuntu.

    • Alternatively, if you want to make a user an administrator (so they can perform administrative actions including running commands as root with sudo):

      In Ubuntu 12.04 and higher (you can run lsb_release -r to see what version of Ubuntu you have, just make sure you run it in the chroot or it will tell you what version the live CD has), run:

      usermod -a -G sudo username

      In Ubuntu 11.10 and lower, administrative abilities were conferred by membership in the admin group rather than the sudo group. So then you would instead run:

      usermod -a -G admin username

      In both cases, replace username with the name of the user account you want to give admin powers.

  10. Run these three commands:

    exit
    sudo umount /mnt
    exit
    

    The last of those commands quits the Terminal window.

  11. Reboot the system by clicking the power icon on the upper-right corner of the screen and clicking Shut Down. (Then click Restart in the dialog box that comes up.) Make sure to remove the CD/DVD or USB flash drive before the system boots up again, so that you can get into your Ubuntu system on the hard disk.

    • If you're running an old enough Ubuntu live CD that there is a Restart option in the power menu, you should click that rather than Shut Down.

If You Cannot Use The Installed Ubuntu System At All

If you can't log on to obtain the device name of the partition that contains your Ubuntu system's root filesystem, you can figure it out after booting the live CD. There are several ways to do this. I present the one here that I consider easiest and least likely to lead to mistakes. (However, you may also be interested in this other method.)

  1. If you don't already have one, burn an Ubuntu live CD/DVD (on Ubuntu, Windows, or Mac OS X) or write an Ubuntu live USB flash drive (on Ubuntu, Windows, or Mac OS X).

  2. Boot the computer from the live CD/DVD/USB and select Try Ubuntu without installing (not Install Ubuntu).

  3. Open GParted.

    • To do this in Unity, which is the default desktop environment in most versions of Ubuntu, click the home button (i.e., the button at the upper-left corner of the screen with the Ubuntu logo on it) or press Super, which is also known as the Windows key. Then type in gparted. GParted will come up, and you can click it.

    • Ubuntu 17.10 and later use GNOME 3 with the GNOME Shell instead of Unity. To open GParted, click on the grid of nine dots that appears on the lower-left corner of the screen to open the application panel. Then click on the GParted icon.

      Two screenshots of GNOME 3 with the GNOME Shell in an Ubuntu 17.10 live environment, contributed by Videonauth, placed side by side, with hand-drawn markings added to show where the button is for the *applications panel*, as well as what the GParted icon looks like in the applications panel. Note that this icon is labeled GParted, so it is not necessary to recognize it by the appearance of the icon.
      Special thanks to Videonauth for explaining how to open GParted in GNOME 3, as well as for providing these screenshots.1

    • On very old versions of Ubuntu that use GNOME 2 instead of the Unity or Unity 2D interface, open GParted from the top menu by clicking SystemAdministrationGParted Partition Editor.

    • Other Ubuntu flavors, like Ubuntu MATE, Xubuntu and Lubuntu, have a similar system of nested menus, through which you can access GParted while running them from a live USB or live CD/DVD.

  4. Now you can see all your partitions graphically. If you have more than one drive, you may need to select the one that contains your Ubuntu system, in the drop-down menu at the upper-right corner of GParted.

  5. The partition that contains your Ubuntu system's root filesystem is most likely a large partition of type ext4 (or for very old Ubuntu systems, ext3). Usually there is only one ext4 (or ext3) partition, or just one big one. Otherwise, one might be the / partition (containing the root filesystem, this is what you want) and the other might be the /home partition. So if there are two large ext4 or ext3 partitions, you can assume the first one (shown farthest to the left) is probably the one that contains your system's root filesystem.

    This could possibly be wrong, but nothing will be damaged by these instructions if you are. In some other situations, outside the actions described in this post, it would not necessarily be safe to make this assumption.

  6. Remember, or write down, the device name of the partition that (probably) contains the root filesystem. GParted shows this to you. It usually takes the form /dev/sdXn where X is a lower-case letter and n is a number.

  7. Quit GParted.

  8. Follow the instructions above ("If You Can Log On as a Non-Administrative User"), starting with Step 6.

These post was originally adapted from post #9, which I wrote, in this Launchpad Answers question.

1 Credit goes to Videonauth for explaining to me how to launch GParted in an Ubuntu 17.10 live environment. I don't have GNOME 3 and would not have been able to provide those instructions otherwise. He also supplied both screenshots. (All I added were the ugly hand-drawn arrow and circle.)

  • Thanks. Accepting this because it addresses the issue that I encountered (which is what to do if the regular "password reset" options do not work). Not entirely sure if this will work because I already formatted the system, but I believe this could very well work. – please delete me Jun 8 '12 at 23:17
  • 1
    Considering different scenarios, describing each step in details, and most importantly solving the problem that I couldn't find the answer anywhere else, made this answer by far the best answer I've ever seen in the community. I would upvote it 100 times if I could! – Navid Vafaei Sep 1 at 21:18

If you need to change your root password but do not know the old one. You will need to drop to a root shell. When you boot into your computer, as soon as the bios screen disapperes (the srceen with your computers logo on it), start tapping the Shift key untill the grub menu comes up, and if this option does not work, then tap the esc key. (if it is already configured to come up then this step is not nessessery)

When you see the menu choose the option of the latest kernel (or the one you normally use) and choose the option right below called "recovery mode" It should look like this:

enter image description here

This will take you to a menu looking something like this: enter image description here

Next choose the Root option

Wait and let everything load untill you get to a shell. Now comes the fun; Enter the following command:

passwd "your username"  
(no qoutes though)

If you are unsure of your username you can look at the names of the files in your home floder via:

cd /home

than enter

ls

This will show you the names of users on your computer.

Now type the command I stated above; passwd "your username" without the qoutes. So that if your username is jane, I would type:

passwd jane

Next you will be presented with an option to enter your new unix password. This is where you enter the password. It will ask you to retype the command and then after two successful passwords were entered the password has been changed. Now log back into your system via

reboot

If you are asked for your root password when entering your new password this will usually help:

Second Possible Step

"If you get asked for the root password when entering single user mode use 'init=/bin/bash' on the kernel append line which should boot the machine into a bash console where you can get read/write access to your /etc/shadow file. You can then either run passwd or edit the shadow file directly to put in an empty string. This allows you to reboot the machine into its normal environment and login as root leaving the password blank and then run the passwd program to set the root password. This should really only be done when the machine is detached from any networks." (taken from shawn lee in an article mentioned below)

If you need more information these links can help:

https://wiki.ubuntu.com/RecoveryMode

http://www.psychocats.net/ubuntu/resetpassword

http://www.debuntu.org/recover-root-password-single-user-mode-and-grub

http://www.debianadmin.com/how-to-reset-debian-root-password.html

  • 1
    The problem is, that he has the root password set, so he cannot drop to root shell unless he writes it. But he doesn't know it. – gajdipajti Apr 13 '12 at 20:35
  • Thanks, but the first step as mentioned is not working. I have tried the second option, but the screen remains blank after I edit grub and try to boot. The computer did not have critical data on it so I chose to format it at the end, it seemed the easiest way. – please delete me Apr 14 '12 at 1:40
  • Problem is now the root filesystem needs to mounted first, either through remounting with mount, or the networking option – Wilf Oct 3 at 16:49

If there is a root password set and you have forgotten it, but can boot normally and can use sudo try this from a terminal

sudo passwd -dl root

It is not apparent if you are getting the normal (and sudo) password and a root one confused.

The links you have for resetting passwd whould normally work.

Here. this might help How to reset your password in Ubuntu
or simply At your Grub menu, choose "Recovery Mode", then at the prompt type

passwd "your username" without quotes obviously

protected by Community May 31 '16 at 5:55

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.