1

My laptop screen has been damaged, so I have a separate monitor connected, but when I'm in recovery mode the separate monitor doesn't get the signal from the laptop so I can't see what the screen says while I enter commands.

Is there a way to change the password without recovery mode and through the terminal?

0

1 Answer 1

1

TL;DR: You should be able to boot to a live environment, chroot in, and reset the password.


The challenge you've described is that when you run the system normally, your external display is used, but in recovery mode, it isn't. If you can boot into a live environment, such as from an Ubuntu live USB or live DVD, your external display will probably work there. If it does, you can change passwords from the live environment (see below).

Simply inserting the live medium and rebooting may be sufficient to boot from it. This depends on the boot order that is set in your computer's firmware (i.e., BIOS or UEFI). Although it's possible to configure Ubuntu's boot loader to boot a different device on the next boot, and even sometimes to change your firmware's boot settings from within Ubuntu, both these actions would require that you be able to run commands as root within the Ubuntu system, which you cannot currently do.

Even though recovery mode doesn't use the external display, I would not assume that your computer's firmware setup won't. You should try it, if the machine doesn't just boot from a live USB or live CD/DVD when you reboot with it inserted (see below). Which key or keys to hold down to bring this up vary by manufacturer. Some machines also have a separate key or key combination to hold down to bring up a menu on which you select which device to boot from just one time. You can look these both up based on the model of your computer.

If you can't boot the system into a live environment, perhaps someone else will come up with an alternative solution. If ultimately you cannot find a software-based approach, you can take the hard disk out and put it in an enclosure, where you can then freely modify its contents from another machine. You might even be able to do it from the same machine, since without the internal drive it should fall back to booting from a USB flash drive or DVD that is inserted, and you can attach the enclosure after the live system is booted.

The instructions below are for the case where you can boot into a live environment and your external display works in it. They are adapted and shortened from the "If You Can Use the Installed Ubuntu System, Even As a Non-Administrative User" section of my answer to How do I reset a lost password (using recovery mode requires me to type the password)?

One of the ways I shortened them is to cover only the case of changing passwords, and not that of making a user an administrator. Note that the numbering of steps is not the same. For more details, I recommend looking at my original answer. Some answers to How do I reset a lost administrative password? also cover chroot-based techniques.


  1. If you don't still have the USB flash drive or CD/DVD you used to install Ubuntu, make a new one. Note that if you do have it but you upgraded so it's for an older version of Ubuntu, that's fine. If you have a live CD/DVD or live USB for a different GNU/Linux operating system, that's likely to work, too.

  2. Unless you know the device name of the partition that contains your Ubuntu system, don't boot into the live environment yet. In the installed system, open a terminal window (Ctrl+Alt+T) and run this command, including the spaces before on and after /:

    mount | grep ' on / '
    

    You should see something like:

    /dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0)
    

    The text before on, in this case /dev/sda1, is the device name of the partition that contains your Ubuntu system's root filesystem. Remember it, or write it down.

  3. Boot your computer from the live USB or live CD/DVD. Select Try Ubuntu without installing.

  4. Once the desktop has come up, open a terminal window (Ctrl+Alt+T).

  5. Run

    sudo mount /dev/sda1 /mnt

    but replace /dev/sda1 with the device name of the partition containing the root filesystem, if different.

    If you get an error about how a device or partition does not exist or about an "unknown filesystem type," your root filesystem is probably not on the device you specified.

  6. Run:

    sudo chroot /mnt
    

    Some chrooting procedures involve setting up additional mounts in the chroot, such as as /proc. That's not needed for what we're doing here.

    If the partition you mounted in step 5 exists but is the wrong one, you may see this error message:

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

    If you do, run sudo umount /mnt to unmount the partition, then mount the correct one.

    All subsequent steps must be run in the terminal where you ran chroot, unless stated otherwise.

  7. You likely know your username, but if you don't, run:

    ls /home
    

    Or, if you prefer, you can run ls /mnt/home outside the chroot. In either case, this is usually an effective way to list the human users on the installed system. You should be able to find your username that way. If you never made any other user accounts, it should even be the only output of that command.

  8. Reset the password by running

    passwd username

    but write your actual username instead of username.

    If there are no error messages, it worked.

  9. Leave the chroot and unmount the installed system's root filesystem by running these commands, the last of which closes the terminal window:

    exit
    sudo umount /mnt
    exit
    
  10. Use the menus in the live environment's desktop to reboot (check the upper right if the user interface differs from the one you're used to). Or it would even be okay to run sudo reboot in a terminal.

    You may need to remove the live USB or live CD/DVD to boot into your installed system.

In the installed system, you should again be able to run commands with sudo and pkexec and perform other actions that require you to enter a correct password.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .