19

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

2 Answers 2

22

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. 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' " Commented 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
    Commented Feb 5, 2021 at 8:48
  • Looks like it worked, thank you very much for your patience and your help! Commented Feb 5, 2021 at 10:16
50

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.

7
  • 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
    Commented Nov 29, 2022 at 19:40
  • 3
    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
    Commented Nov 29, 2022 at 20:29
  • 2
    For me there was no root user su - with changeme also did not work. The autoinstallation is totally broken. How should a user that just wants to try Ubuntu/VirtualBox figure that the default autoinstallation will create the absolute worst experience. Took me quite a while to realise all of that. Btw my terminal application also did not open, I had to use a tty (or whatever the Ctrl + Alt + F Windows are called) That was the nail in the coffin I tried for 5h (VBox on Mac, WSL2, now VBox in Win) to change the shadows for my rbpi. Thanks for providing the info with the flawed autoinstaller
    – Lukas
    Commented Feb 10, 2023 at 23:24
  • 2
    This worked for me. You have to use the password of your user after invoking su -, not changeme.
    – Hirt
    Commented Apr 18, 2023 at 21:24
  • 2
    To clarify Hirt's answer, after entering su - in VirtualBox 7, I had to enter the password of the user that I created during installation (which was in fact the user I wanted to add to sudoers), not changeme.
    – anthemion
    Commented Apr 25, 2023 at 1:20

You must log in to answer this question.

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