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?
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.
If You Can Use the Installed Ubuntu System, Even As a Non-Administrative User
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).
If you know the device name of the partition that contains your Ubuntu system's root filesystem, feel free to skip to step 5.
In your Ubuntu system (not the live CD/DVD/USB system), run this command in the Terminal:
You should include the spaces before
on
and after/
.That command produces something like
/dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0)
as the output. The text beforeon
(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).Boot the computer from the live CD/DVD/USB and select Try Ubuntu without installing (not Install Ubuntu).
Open up a Terminal window (Ctrl+Alt+T).
Run this command:
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
.Run this command:
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
:If that does happen, then you can unmount it with
sudo umount /mnt
and then proceed to mount the correct partition.Perform one of these tasks, to obtain/restore access to the install Ubuntu system.
If you want to reset a user's password:
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:
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 thepasswd
command with no arguments to resetroot
's password: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
withsudo
):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 thechroot
or it will tell you what version the live CD has), run:In Ubuntu 11.10 and lower, administrative abilities were conferred by membership in the
admin
group rather than thesudo
group. So then you would instead run:In both cases, replace
username
with the name of the user account you want to give admin powers.Run these three commands:
The last of those commands quits the Terminal window.
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 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.)
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).
Boot the computer from the live CD/DVD/USB and select Try Ubuntu without installing (not Install Ubuntu).
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.
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 System → Administration → GParted 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.
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.
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 oneext4
(orext3
) 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 largeext4
orext3
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.
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
whereX
is a lower-case letter andn
is a number.Quit GParted.
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.)
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 disappears (the screen with your computers logo on it), start tapping the Shift key until 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 necessary.)
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:
This will take you to a menu looking something like this:
Next choose the Root option.
Wait and let everything load until you get to a shell. Now comes the fun. Enter the following command:
Replace
your-username
with your actual username.If you are unsure of your username you can look at the names of the files in your home folder via:
Then run:
This will show you the names of users on your computer.
Now type the command I stated above:
passwd your-username
. So that if your username is jane, I would type: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
If you are asked for your root password when entering your new password this will usually help:
Alternative Method
(Quote taken from Shawn Lee in an article listed below.)
To boot with
init=/bin/bash
as suggested, access the GRUB menu at boot time and press e to enter the editor. Move the cursor to the line starting withlinux
and then move the cursor to the end of that line. Enter the textand press F10 to boot. You should land in a root shell in text only mode. The filesystem will be mounted read only. To make the filesystem writable, enter the command
You can then run
where
username
is the name of the user whose password you want to set. When done, you can reboot with thereboot
command.If you need more information these links can help:
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
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.