Wednesday, February 14, 2018

Ubuntu: how to reset lost administrative password

After an extended vacation, I came home to discover to my horror that I could no longer login to my seldom-used Ubuntu laptop. The reason was embarrassingly simple: I forgot my password. My muscle memory (or finger memory) did not help while I was frantically typing my usual passwords but to no avail. I own the administrative account on that system. So, I had no one else to turn to for help. Luckily, I was able to login another machine and google how to reset the administrative password on Ubuntu.

Prerequisites

There are 2 preconditions for using the procedure to reset the administrative password.
  1. Physical access to machine.
    You need to access the system console in order to interrupt loading of the OS.
  2. The root password was disabled.
    By default, Ubuntu disables the password of the root account by assigning it a value which cannot possibly match any encrypted value. During the installation of Ubuntu, you were asked to create the first user. That initial user, by default, belongs to the sudo group which means that the user can be elevated to perform system administration functions. The administrative password which we are going to reset refers to the password of the initial user.
    The procedure assumes that you did not manually assign root a valid password. If root has a valid password and you know it, then you can simply sign on as root and reset the administrative password using the password command. If the root password was also forgotten, this procedure does not apply because you need to enter that password to drop to root shell prompt in this procedure.

How to reset administrative password

  1. Power recycle.
    After the BIOS screen appears, press down the left shift key to enter GRUB. This step can be quite finicky, and you may need to repeat it several times until you get the timing just right.
  2. Scroll down to Advanced options for Ubuntu, and press Enter.
  3. In the ensuing screen, scroll down to the top Recovery mode line, and press Enter.
    If the Linux kernel image had been upgraded on the machine before, you would see multiple recover mode lines on the screen. Select the recovery mode line that corresponds to the latest Linux image(that is nearest to the top).
  4. In the Recovery Menu screen, scroll down to root, and press Enter.
  5. Press Enter again.
    If you have previously assigned root a password, you would be prompted to enter it at this step. Otherwise, just press Enter to continue.
  6. Remount filesystem.
    After all the hard work, you are now at the root shell prompt. The filesystem at this point is read-only. Remount the file system to add write permission.
    # mount -o rw,remount /
    
  7. Reset administrative password.
    Use the passwd command to change the password for the administrative user.
    # passwd <adminuser>
    
    Press Control-D to return to the recovery menu.
  8. Select resume.
  9. Exit recovery.
    Press OK to exit recovery mode and continue booting.

Thursday, February 1, 2018

How to mount USB drives on VirtualBox


This is part 3 of the 4-part series on VirtualBox. This post shows you how to access, from your guest OS, a flash drive mounted on the Debian host. Parts 1, 2 and 4 demonstrate how to build a FreeBSD virtual machine using VirtualBox on a Debian host, perform post-installation tasks, and share folders.

Prerequisites

The VirtualBox extension pack must be installed on the VirtualBox host. See part 2 for instructions.

Configuring USB

Follow the steps below to configure VirtualBox USB.
  1. Add user to vboxusers group.
    VirtualBox access to the host's USB drives is only granted to users of the vboxusers group. As root on the host, run the following command to add each VirtualBox user (e.g., peter) to the group.
     # usermod -aG vboxusers peter
    
  2. Power off VM.
    VirtualBox defaults to using USB Controller 1.1 (OHCI). Modern hardware uses USB Controller 2.0(EHCI) and USB Controller 3.0(xHCI). Before you can change the USB controller protocol, the virtual machine must be powered off.
  3. Open VirtualBox Manager, click Settings, and select USB.
  4. Specify USB Controller.
    Select either USB 2.0 (EHCI) Controller or USB 3.0 (xHCI) Controller according to your actual hardware.

    Note that you can add USB Device Filters to define the types of USB drives which will be automatically made visible to the guest OS. Be forewarned that the USB drive, once made visible to the guest OS, will no longer be available to the host. More on the use of device filters in the next section.

Accessing USB drive

Below is the step-by-step procedure to mount and access a flash drive.
  1. Insert the flash drive into your host machine's USB port.
  2. Unmount the flash drive (if it is auto-mounted on your host).
    Making it available to the guest will automatically and instantly unmount it from the host. To avoid any data loss due to pending writes to the drive, it is a good practice to explicitly unmount the drive prior to handing control to the guest.
  3. Power on the FreeBSD guest.
  4. Assign USB drive to guest OS.

    Open the virtual system console, and right click the USB drive icon.

    Click to select your USB drive.

    Note that this is a 1-time assignment only. Please see instructions at the end of the section on how to automatically assign this particular USB drive for all subsequent sessions.
  5. Login to FreeBSD, and mount the drive.
    You can mount a MS-DOS based flash drive by running the following commands as root. Replace /dev/da0s1 with the proper device identifier for your USB drive. (You can find out the exact device ID by first running dmesg to identify the device name, e.g. da0, and fdisk to reveal the disk partition structure, e.g., s1.)
     # mkdir -p  /media/usb
     # mount -t msdosfs  /dev/da0s1  /media/usb
    
    To unmount the drive,
     # umount /media/usb
    
To always automatically assign a particular USB drive to the guest OS, open the VirtualBox Manager, click Settings, and then USB.

Finally, click Add USB device filter (with the + sign) icon, and select the USB drive that is currently inserted in the host.

Related posts