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)?
irrelevant relevant - answer updated to account for VirtualBox 7 and its unattended installations.
Defaults for Ubuntu are:
- Login to
rootaccount is disabled
- Members of group
sudoare granted full
- A user account is created during installation and added to the
When you're logged in into that account, you should be able to use the
However, VirtualBox 7 will by default have "unattended installation" enabled, which sets up Ubuntu differently:
- Login to root account is enabled - default password is
- User account is created - default user/password are
- 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:
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)
Select root - Drop to root shell prompt. Execute this command to add
yourUsername to the
adduser yourUsername sudo
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
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.
sudo adduser [username] sudo
[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.