4

I have Windows 10 installed on my computer. I installed Oracle VirtualBox and created a machine with Ubuntu 20.04. I need administrative privileges on this machine but, for some reason, I cannot have them. I have read that Ubuntu automatically creates a root account that acts as admin, and that you need to use "sudo" before your command to run it with admin permissions. It asks for my password, I insert it and then the system tells me that my account is not a sudoers so the operation will be reported. I have already tried different tutorials to create a sudoer account, but they all require that you are already using one. So, how do I change my own account to a sudoers one? Or, alternatively, how do I create a new sudoers account from zero with this kind of admin privileges (in the Virtual Box)?

2 Answers 2

7

Virtualbox is irrelevant relevant - answer updated to account for VirtualBox 7 and its unattended installations.

Defaults for Ubuntu are:

  • Login to root account is disabled
  • Members of group sudo are granted full sudo privileges
  • A user account is created during installation and added to the sudo group

When you're logged in into that account, you should be able to use the sudo command.

However, VirtualBox 7 will by default have "unattended installation" enabled, which sets up Ubuntu differently:

  • Login to root account is enabled - default password is changeme
  • User account is created - default user/password are vboxuser/changeme
  • The user account is not a sudoer

The easy way out of this situation is described in the answer by Retr0Rob.

The slightly more complicated, but also more universal method is described below. It lets you make any user a sudoer by accessing the root account even if it's disabled or you don't know the password. It works both for VMs and physical computers.

When the machine is booting, immediately start pressing Esc repeatedly. You should see the GRUB screen:

GRUB screen: black background, white text, large rectangle taking up most of the screen.

Using arrows and Enter select Advanced options for Ubuntu, then Ubuntu, with Linux [...] (recovery mode) (2nd option from the top). You should see something like this: (although older Ubuntu versions won't be so colorful)

Ubuntu recovery mode menu

Select root - Drop to root shell prompt. Execute this command to add yourUsername to the sudo group:

adduser yourUsername sudo
3
  • As you said, I've somehow precluded to myself the sudo privileges (really don't know how). Anyway, I've tried your solution but I have two problems: 1) since I'm basically a noob, I don't exactly understand "where" I have to insert "single" in the screen that I obtain. 2) I pressed c to enter the root shell and used the command line "adduser myname sudo" as you suggested, but the systems says "error: can't find the command 'adduser' " Feb 5, 2021 at 8:32
  • c opens the GRUB shell, not Linux shell (Linux hasn't even booted yet). That's not what you're looking for. Please see this question on our sister site. (I've found it by googling "ubuntu single user mode")
    – gronostaj
    Feb 5, 2021 at 8:48
  • Looks like it worked, thank you very much for your patience and your help! Feb 5, 2021 at 10:16
11

VirtualBox is TOTALLY relevant to the question.

This can happen if you chose to have VirtualBox automatically create your first user for you when setting up Ubuntu. The first user is not added to sudoers as one would expect.

To fix it go into terminal and

  1. type su -

This will log you in as root. Your prompt should change to a "#" explanation: VirtualBox automatically set the root password as the same as your user password. It's not great behavior, but that is what it does.

  1. type sudo adduser [username] sudo

Where [username] is your user name. This adds your user to the sudo users list.

You may want to reboot or logout and log back in to have the changes take effect.

2
  • 1
    Can you explain when exactly VirtualBox sets up a user account? I know VMware has "setup enhancers" like this, but I've been using VBox for 10 years and I haven't seen such thing. I don't think it's aware of Ubuntu's internals at all - it just emulates/virtualizes the hardware. I'm installing Ubuntu in VBox like once a week on average and every single time I'm getting the same setup I would get on bare metal: single account, added to sudoers, root account disabled and doesn't have a password. Neither VBox nor Ubuntu seem to care about each other.
    – gronostaj
    Nov 29, 2022 at 19:40
  • Okay, VirtualBox 7 (released in October 2022) has added unattended installs - that's probably what you're referring to. This feature wasn't present when the question was asked and I was only made aware of VBox 7 being a thing this morning, so pardon my confusion ;) Indeed, the VM gets set up with a single non-sudoer user account + enabled root account with the same password. It's probably a good idea to update my answer.
    – gronostaj
    Nov 29, 2022 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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