805

I'm working on a Ubuntu system, and my client has completely forgotten his administrative password. He doesn't even remember entering one; however it is there.

I've tried the suggestions on the website, and I have been unsuccessful in deleting the password so that I can download applets required for running some files. Is there a solution?

6

16 Answers 16

949

By default the first user's account is an administrative account, so if the UI is prompting you for a password it's probably that person's user password. If the user doesn't remember their password you need to reset it. To do this you need to boot into recovery mode (see also offical docs: RecoveryMode).

Boot up the machine, and after the BIOS screen, hold down the left Shift key (note that for UEFI BIOS you might need press ESC instead). You will then be prompted by a menu that looks something like this:

enter image description here

I've noticed on some systems that timing when to hit the left Shift key can be tricky, sometimes I miss it and need to try it again.

Hit the down arrow until you select the 2nd entry from the top (the one with the recovery mode in the description) and then hit Enter.

Now you should see this menu:

enter image description here

Using the arrow keys scroll down to root and then hit Enter.

You should now see a root prompt, something like this:

root@ubuntu:~#

At this stage you should have a read-only filesystem. You have to remount it with write permissions:

mount -o remount,rw /

Now we can set the user's password with the passwd command. (In this example I will use jorge as the example, you need to substitute whatever the user's username is):

root@ubuntu:~# passwd jorge
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@ubuntu:~#

Type in what you want the new password to be at the prompt. After it's successful reboot the machine and the user will be able to log in with their new password.


There is concern about this being a security vulnerability. It is not. You need to have physical access to the machine to do this. If someone has physical access to your PC, they could do far worse than change a password. When it comes to physical access, the battle for security is lost. Be wary of who you let on your PC.

Even setting a root password will not be successful, as one can simply boot with init being /bin/sh and have full root access. Again, given physical access, anyone with computer knowledge can do ANYTHING to your computer.

15
  • 24
    Google needs to learn this. Jul 28, 2018 at 18:13
  • 9
    I didn't have to remount
    – Aadishri
    Oct 24, 2018 at 16:07
  • 1
    Lenovo Laptop is painful to get to recovery mode. The solution is just after BIOS (i.e. Lenovo logo) press "ESC" holding the left shift key. Jan 11, 2019 at 7:03
  • 2
    "select the 2nd entry from the top" - that might not be accurate, in my case 2nd entry was (upstart), not (recovery mode) Mar 7, 2019 at 20:18
  • 5
    In Ubuntu 18.04, GRUB root required me to enter the root password: askubuntu.com/questions/121698/… Nov 12, 2019 at 12:35
85

Yes, you can change the old password via GRUB.

  1. If you have a single-boot (Ubuntu is the only operating system on your computer), to get the boot menu to show, you have to hold down the Shift key during bootup.

  2. If you have a dual-boot (Ubuntu is installed next to Windows, another Linux operating system, or Mac OS X; and you choose at boot time which operating system to boot into), the boot menu should appear without the need to hold down the shift key.

  3. From the boot menu, select recovery mode, which is usually the second boot option.

  4. After you select recovery mode and wait for all the boot-up processes to finish, you'll be presented with a few options. In this case, you want the Drop to root shell prompt option so press the Down arrow to get to that option, and then press Enter to select it.

  5. Once you're at the root shell prompt, if you have forgotten your username as well, type ls /home (small letters & not capitals). This will list all the user accounts in your set up.

  6. To reset the password, type passwd username where username is the username you want to reset, for example, passwd mysterio in my case.

  7. You'll then be prompted for a new password. When you type the password you will get no visual response acknowledging your typing. Your password is still being accepted. Just type the password and hit Enter when you're done. You'll be prompted to retype the password. Do so and hit Enter again.

  8. Now the password should be reset. Type exit to return to the recovery menu.

  9. After you get back to the recovery menu, select resume normal boot, and use Ubuntu as you normally would — only this time, you actually know the password!

2
  • 3
    This offers a route for when you forget both userid and password, which would also work with @Jorge Castro's answer.
    – Bobble
    Oct 3, 2012 at 0:59
  • The Recovery Menu (step 4 in @Mysterio's list) never came up for me, but I was able to cobble together an alternate solution here.
    – Karl Baker
    Mar 29, 2019 at 2:34
64

If you forgot the password for your Ubuntu system you can recover using the following steps:

  1. Turn your computer on.

  2. Press ESC at the GRUB prompt.

  3. Press e for edit.

  4. Highlight the line that begins kernel ......... or linux ........, press e

  5. Go to the very end of the line and add rw init=/bin/bash

  6. Press Enter, then press b to boot your system. Your system will boot up to a passwordless root shell.1

  7. Now issue the command passwd username *where "username" is the user for which you want to change the password.

  8. Then you will be asked to give new password:

    Enter new UNIX password:

1Source: ubuntugeek

Other resources:

For Xubuntu 14.04 just follow the screens below. It's similar to some of the other answers.

Press Esc, and choose Advanced options

Enter image description here

Choose recovery mode:

Enter image description here

Then choose root, and once you get the prompt type passwd <user_name>, to change the password.

Enter image description here

10
  • The OP may not know what to do at the shell.
    – nanofarad
    Jul 18, 2012 at 20:10
  • Did not work in Xubuntu 14.04 LTS - no command in GRUB2 beginning kernel or linux.
    – K7AAY
    Apr 25, 2014 at 3:52
  • @K7AAY see my addition for Xubuntu 14.04.
    – Mitch
    Apr 25, 2014 at 12:17
  • 3
    you are life saver its worked for me in ubuntu 14.04
    – Maulik.J
    Jul 8, 2014 at 19:20
  • 2
    In step 5, worked for me when I also removed "ro" if present, while adding "rw". May 22, 2016 at 15:16
58

If Jorge's method didn't work for you, as it didn't for me, here is another method. I had to try something different because:

  1. My USB keyboard did not work at the root prompt ⋯ probably hardware either keyboard or mainboard. To fix I used an old PS/2 keyboard (the little round plug) and use that.

  2. When I used passwd username to change my password, it failed because of a bad token or such. This called for drastic measures.

The Drastic Measures

This is a very dangerous thing to do! Jorge's method should be used; only do this in case that method doesn't work.

Do this at your own risk. It did work for me on my 11.10 system.

The idea is to set the user's password to blank (or null) - this allows you to just press Enter at the Password: prompt.

Still at the root prompt from Jorge's method, first remount the root file system as read-write by using this command:

mount -o remount,rw /
  • Now you are a super-user on this system. Tread lightly.

Then edit the password shadow file to remove the encrypted password for your username. Type in:

nano -B /etc/shadow

The nano editor will display the contents of the file. Each line will have the form name:⋯:⋯:⋯… where ⋯ is a string or null (empty). One of the lines will start with your username. The first ⋯ after your username is your encrypted password. As an example:

username:$1$amFeNcjp$PprjCKEVk3UtzKwWfEMOY0:14920:0:99999:7:::

where $1$amFeNcjp$PprjCKEVk3UtzKwWfEMOY0 is the encrypted password.

Carefully delete the encrypted password leaving the all the ":"s, so it looks like this:

username::14920:0:99999:7:::

Then type Ctrl+O, press the Enter key to save, then Ctrl+X to close nano.

Reboot and you will have an empty (or null) password. Be sure to use passwd username in a terminal to set or reset your user password.

Source for PS/2 workaround was here.

Sources for the drastic measures were here and here.

Note on nano ― the -B option makes a backup of the original edited file, same name with a "~" appended.

6
  • 5
    You can also use this method by booting with a different disk and editing /etc/shadow after mounting the appropriate disk.
    – Mei
    Mar 29, 2012 at 23:52
  • 2
    Or by booting a live CD/USB version. Again this is why physical access to a PC negates all security measures.
    – DaveM
    May 17, 2015 at 7:13
  • 1
    @DaveM almost all. Full disk encryption is still not defeated easily. :) Jun 10, 2016 at 8:51
  • 1
    @AndreaLazzarotto fair point. Would it also be possible using the live CD, chroot into the 'main' system, and perform a password modification ?
    – DaveM
    Jun 13, 2016 at 16:28
  • 1
    Just stumbled across this very helpful answer. But...just wondering if a clarification of the above would be good for new users. In particular, the bold face around the text that says it is a "dangerous thing to do". It is dangerous because the administrator no longer has a password set; but if you have control of the situation and (for example) are able to physically unplug it from the network before starting, then I don't see it being dangerous any more. I'm not sure if I missed other reasons why it would be so dangerous.
    – Ray
    Sep 21, 2018 at 2:38
32

If recovery mode is disabled, the method I would use is booting to a Live CD or USB. It could be the media you installed from or just another Ubuntu ISO you've downloaded and burnt. The process is fairly simple.

  1. Boot to the Live media.
  2. From the menu, open a terminal.
  3. Find out the device name for your primary disk. sudo fdisk-l will list all partitions. Derive your partition from the list. We're looking for something like /dev/sda1 (which it will likely be)
  4. Mount this somewhere so we can use it (obviously change the disk to the right one):

    sudo mount /dev/sda1 /mnt
    
  5. Cross-mount things from the Live install so we can "use" the mounted disk (just copy and paste):

    for d in dev sys run proc; do sudo mount --bind /$d /mnt/$d; done
    
  6. Become root on the system by running sudo chroot /mnt. You can now do anything root can on the real install.

  7. Set the password for the account:

    passwd username
    
  8. Reboot and you're done.

2
  • Worked like a champ in Xubuntu 14.04 LTS. Recomended.
    – K7AAY
    Apr 25, 2014 at 3:51
  • 1
    If you have a lvm partiton, you need to mount it to /mnt/ first and then mount dev sys run proc respectivily.
    – Achu
    Jul 31, 2015 at 6:50
28

Ubuntu does not come with an Administrative password. There is only one initial account, the user account, which can be used to execute administrative tasks. For example, to get a root shell you run

$ sudo -i
[sudo] password for myuseraccount:         # here you type the user's password
# 

A lot of people that have Unix background or experience with other distributions stumble on this issue quite often.

The command

su 

will always fail because the root account is locked; it cannot be accessed directly or you cannot login directly to root.

There are great advantages in using the sudo facility.

2
  • megathanks! I thought that my remote server will always run with current config because I forgot root's password! )) Jul 20, 2015 at 11:07
  • thank you.! ^_^
    – Deidrei
    Sep 25, 2022 at 19:42
26

From the official Ubuntu LostPassword documentation:

  1. Reboot your computer
  2. Hold Shift during boot to start GRUB menu
  3. Highlight your image and press E to edit
  4. Find the line starting with "linux" and append rw init=/bin/bash at the end of that line
  5. Press Ctrl+X to boot.
  6. Type in passwd username
  7. Set your password.
  8. Type in reboot. If that doesn't work, hit Ctrl+Alt+Del

This works for Linux Mint 14, too.

2
  • 4
    I was working on a computer whose user had lost both the admin and the root passwords. This is the only method that solved his problem, thanks! Jul 14, 2013 at 12:59
  • 1
    I had to add mount -rw -o remount / before step 6, otherwise I get the error "Authentication Token Manipulation Error" Jan 25, 2022 at 8:47
14

First, you have to reboot into recovery mode.

If you have a single-boot (Ubuntu is the only operating system on your computer), to get the boot menu to show, you have to hold down the Shift key during bootup. enter image description here From the boot menu, select recovery mode, which is usually the second boot option. enter image description here After you select recovery mode and wait for all the boot-up processes to finish, you'll be presented with a few options. In this case, you want the Drop to root shell prompt option so press the Down arrow to get to that option, and then press Enter to select it.

The root account is the ultimate administrator and can do anything to the Ubuntu installation (including erase it), so please be careful with what commands you enter in the root terminal.

Once you're at the root shell prompt, if you have forgotten your username as well, type

ls /home

That's a lowercase L, by the way, not a capital i, in ls. You should then see a list of the users on your Ubuntu installation. In this case, I'm going to reset Susan Brownmiller's password.

To reset the password, type

passwd username

where username is the username you want to reset. In this case, I want to reset Susan's password, so I type

passwd susan

You'll then be prompted for a new password. When you type the password you will get no visual response acknowledging your typing. Your password is still being accepted. Just type the password and hit Enter when you're done. You'll be prompted to retype the password. Do so and hit Enter again.

Now the password should be reset.

Type exit

to return to the recovery menu.

After you get back to the recovery menu, select resume normal boot, and use Ubuntu as you normally would—only this time, you actually know the password!

source

1
  • 1
    I get passwd: Authentication token manipulation error instead. Does not want to change it.
    – demongolem
    Dec 22, 2017 at 14:36
10

I was able to use Jorge's method - the one above with the nice screen shots - with a few minor changes. I'm using Ubuntu 11.10

First, when booting up - don't press the left shift key until the BIOS screen goes black and then immediately press and hold the left shift key.

Then, after perhaps a minute and a number of lines of text scroll on the screen, I got the first menu, but with a couple of fewer lines - I chose the second line.

Then I got the Recovery Menu - but when I chose Drop to Root Shell Prompt (bottom item) I was root but couldn't reset the password - because the disks were Read Only. Type exit and get back to the Recovery Menu

There was a choice (not shown on Jorge's screen shot) to Remount Read/Write Used the down arrow to go to it, then left arrow to get to and Enter - and it mounted the disk RW.

Then again to Drop to Root Shell Prompt and I'm root and can write - so passwd username had me enter the desired password twice - then exit to go back to Recovery Menu Resume normal boot and everything worked fine with my new password! I'm the only account on this box, and my password works with sudo so I apparently have Administrative Privileges.

This was less exciting than editing /etc/shadow but I was glad to trade the excitement for a nice ending.

1
  • For another permutation on Jorge's method, in which no Recovery Menu screen appears, see here.
    – Karl Baker
    Mar 29, 2019 at 16:34
9

I was having the same problem with my password and I tried everyone's suggestions but none worked for me. So I tried some of my own and this is what worked for me... "Keep in mind I can NOT explain why it worked, all I know is it worked...

"10 Easy and Simple steps to Reset Lost or Forgotten Password"

  1. Reboot computer and hold the Left Shift Key down.

  2. Select boot into recovery mode.

  1. After a few seconds you should get the "Recovery Mode Options" screen.

Note: (Here is the part I can't explain. After trying everything, and nothing working, I finally just started trying all the options here one at a time. When I tried the "grub Update grub boot loader" and then followed the rest of the steps all was well and password was reset.)

So before going to the "root Drop to root shell promt"selection,

  1. Select "grub Update grub boot loader", and you should get this screen.

  1. Select "Yes". Wait for it to go through the update.

  2. Now select "root Drop to root shell prompt".

  3. Now you should be at a root terminal with something like the following: youracctname@yourcompname:~$. type passwd accountname ( acountname being the name of the account you are trying to change the password for ).

  4. Enter new Unix password: "enter the new password".

  5. Retype new Unix password: "retype the same password you did in Step-8".

  6. It should confirm successful password change. type exit at the prompt and reboot.

If this does not work for you, try skipping Steps 4 & 5...

1
  • The GRUB update step might be actually necessary to remount the root partition in read-write mode. If it is indeed the case, a cleaner way would be to mount / -o remount,rw before the passwd command.
    – Ale
    Feb 15, 2016 at 19:42
6

You can change your password if you have access to the file /etc/shadow (maybe with your root account, via sudo from another account, from recovery mode, or with a LiveCD/DVD).

This shadow password file has all the users and encrypted passwords (as well as other administrative information) for the system. The fields are separated by : . For example :

YOUR_USERNAME:$6$lCu1.iVo$Q3nAL98jBLe5mMJ.0dBDd1Iquz41dDKsP3UdJ4X92gZPwwmQ0vdIEIY8EQxEcYACoMboYhovrpyq7Tm.DztQB.:15520:0:99999:7:::

The password is the second group of characters after YOUR_USERNAME, between the two colons. You can replace this with a other password, for example, you could replace the existing password string (truncated for clarity):

$6$lCu1.iVo$Q3nAL98jBLe5mMJ.0[...]boYhovrpyq7Tm.DztQB.

with

$6$8gMLdPVn$Ych6r5ysKRqhL9jOlg0UPe28KRuzo3TSYMShqb5pzACrE/A0oyDEBFefOgplbboeoe0T9ZqNz7u6Y8YWuQRkz/

The encrypted string represents "hackme". This would be your new password.

1
  • 2
    Could you add how to generate a new password hash please?
    – Wilf
    Jun 25, 2017 at 10:50
5

No, there is no way to retrieve the old password.

Yes, you can change the password without knowing the old one. The process is described on several sites on the net, easily found via a search on Google

If you do that however and happened to have used an encrypted /home directory for that username you are likely not to gain access to the files in your /home directory (and if you do then Ubuntu should be uninstalled...)

1
  • 3
    You can try to get the old password, actually by cracking it with (e.g. using a program like John, see openwall.com/john). However, if the password is not trivial, this might take an extremely long time.
    – Ale
    Feb 15, 2016 at 19:46
3

For me, on Ubuntu 16.04 VM installed in VirtualBox, when I boot into (with shift held before booting the VM) the root prompt, I always get Give root password for maintenance (or type Control-D to continue), finally I hit e at the GRUB menu with the newest recovery kernel selected in Advanced Options for Ubuntu

Advanced Options for Ubuntu in GRUB menu (kernels list)

and the hit Down scroll to the bottom, and see a line

linux /boot/...  ro recovery nomodeset

I scrolled to this line with Down/Up arrows, and moved to the end of this line of end, and changed ro recovery nomodeset to rw init=/bin/bash, and then hit Ctrl + x.

This will boot you into the system as root, and you can change your password as normal.

GRUB editor screen with arrows to parameters

5
  • 1
    How does this answer the question about resetting a password? nomodeset is not related at all.
    – Pilot6
    Jul 28, 2018 at 15:09
  • @Pilot6 I don't know nomodeset at all, but I when I try replace these things with rw init=/bin/bash, then it works, that's all.
    – Fangxing
    Aug 1, 2018 at 7:03
  • nomodeset is not set by default. You must have added that parameter at some point. In any case, whether you remove it or not, setting init=/bin/bash will cause the system to boot into a Bash shell as described. Note that you can exec /sbin/init from there to complete a normal boot :)
    – Zanna
    Aug 4, 2018 at 18:18
  • Zanna, Thanks for the explanation, but It did set by default in the recovery mode
    – Fangxing
    Aug 5, 2018 at 3:23
  • 1
    @Pilot6, @Zanna, the nomodeset actually is the setting on some systems. My Dell refurb with Ubuntu 18.04 came with ro recovery nomodeset and updating the password requires changing it as @fangxing describes. This may explain why. Also, that value will automatically revert to ro recovery nomodeset on reboot. It just needs to be manually changed for this process.
    – Karl Baker
    Mar 29, 2019 at 2:50
2

In the boot GRUB menu, you may append init=/bin/bash to the kernel boot parameter to get a root shell.

1
  • It is the password of Ubuntu my friend .And I got it done .Any way a big thanks to you too for your kindness Xie.
    – Noah Diaz
    May 12, 2012 at 3:21
2

This is what worked for me.

**PROCEED only if all the following step are familiar and know what happens in each step.**

  1. Boot using live USB
  2. sudo mount /dev/sdb1 /mnt
  3. sudo nano -B /mnt/etc/shadow
  4. remove the encrypted pwd following the user who's password you want to set it to
  5. Save the file and quit nano
  6. Reboot from HDD
  7. login with the user who's password was set to
  8. passwd <user who's password was set to empty>

Go to beach!

1
  • 1
    I didn't have a live USB and the above didn't work for me, but for Ubuntu 18.04 this ended up working.
    – Karl Baker
    Mar 29, 2019 at 2:38
0

Password Recovery

Step 1: Go to Safe mode by holding Shift or pressing Escape key while booting
enter image description here
Step 2: Press E to edit command
Step 3: Search for "linux" and change ro to rw (It should be at bottom)
enter image description here
Step 4: Add init=/bin/sh at end of current line
enter image description here
Step 5: Press Ctrl + X to Reboot

You might need to remove splash $vt_handoff if present.

Now you should get a CLI shell

type nano /etc/shadow
enter image description here
remove all value from $ to : of the account you want to access.
enter image description here
enter image description here
Save the file and then reboot.

You should be able Log in without password.

P.S.
I have tried it on Ubuntu 16.04, not sure if it works on 18.04
Note: This has nothing to do with your BIOS, we are tweaking the GRUB
Good Luck!

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mitch
    Jun 21, 2019 at 7:45

You must log in to answer this question.