Fixing “Username is not in the sudoers file” Error in Ubuntu 22.04 Installed in Virtual Box

When working with Ubuntu 22.04 installed in VirtualBox, you may encounter an error message stating “Username is not in the sudoers file. This incident will be reported” when attempting to run commands with sudo privileges.

Username is not in the sudoers file
“Username Is Not in the Sudoers File. This Incident Will Be Reported” Error in Ubuntu

This error occurs because the user you’re logged in as doesn’t have the necessary permissions to execute commands with administrative privileges.

In this article, we will guide you through the steps to fix this error by adding your user to the sudoers file.

Steps to fix “Username is not in the sudoers file” Error

We will fix these errors by creating an admin user group (if doesn’t exist) which will have root user privileges. Then we will assign our default user to that admin group. So, mutually it will automatically get those missing privileges and the error will go away.

mount -o remount,rw / #to enable filesystem read-write mode
sudo groupadd admin  #to add admin group
sudo usermod -aG admin username  #to assign username to admin group
sudo -l -U username  #to check updated user previleges

Keep reading for a detailed explanation of each step along with screenshots.

Step 1: Accessing Ubuntu recovery mode:

  1. Launch the VirtualBox containing Ubuntu 22.04. (Press Shift key while booting)
  2. When the GRUB bootloader menu appears, select “Advanced options for Ubuntu.”
GNU Grub Boot Options
GNU GRUB Ubuntu Advance Boot Option
  1. Choose the entry with “(recovery mode)” appended to the kernel version and press Enter.
ubuntu recovery mode boot menu
GNU GRUB Ubuntu Recovery Mode Option
  1. In the Recovery Menu, select “root: Drop to root shell prompt” and press Enter. If the root password for maintenance is asked, enter the password you had set at the time of the virtual machine setup for the default user.
ubuntu recovery mode
Ubuntu Recovery Mode Options

Now enter the following command to remount the directory filesystem with read-write mode,

mount -o remount,rw /

Step 2: Add admin user group

After dropping to the root shell prompt, you will see a command prompt that starts with “#”. This indicates that you have root privileges. To create a new group called “admin,” enter the following command:

   sudo groupadd admin
group add in ubuntu
“sudo groupadd” command in Ubuntu

Step 3: Assign username to the admin group

Next, add your username to the “admin” group using the following command:

   sudo usermod -aG admin username
assign user to admin group
“mount -o remount,rw/” and “sudo usermod” commands in Ubuntu

Replace “username” with your actual username on Ubuntu. For example, in the above screenshot, the username is “imran”.

Note: alternatively you can directly use the “sudo” group to assign related privileges to username. Just use “sudo” instead of “admin” in the above command.

Step 4: Verifying the user attributes

You can verify the username’s group association by using the following command,

sudo -l -U username
check user previleges
“sudo -l -U username” command to verify user privileges in Ubuntu

Step 5: Reboot and test changes

Restart your Ubuntu virtual machine by entering the command:


Once the system restarts, log in using your username and password. Open the Terminal by pressing Ctrl+Alt+T or searching for “Terminal” in the application launcher. Test the sudo command by running:

   sudo apt update

If the command executes successfully without any errors, then you have resolved the issue.


This method is 100% working for the mentioned case where Ubuntu is recently installed as a virtual machine using a virtual box. And please note that this method requires a root password if asked so.

If the user privileges are blocked or limited by the administrator root user then such command executions right can be given by himself only. As a low-privilege user without root access, you cant modify the sudoers file.

1 thought on “Fixing “Username is not in the sudoers file” Error in Ubuntu 22.04 Installed in Virtual Box”

Leave a Comment

Related Posts