33

I've installed a Ubuntu 22.04 VM on my windows computer (using virtual box), and whenever I use the sudo command on the unique, default session, I get the error "user not in sudoers file". How can I fix this ? I have tried to run the recovery mode in root mode, but I'm asked a password (which I never defined nor was given). Isn't it weird that the default session doesn't have admin permissions ? I'm guessing this isn't usually the case, but it's been like this on every ubuntu vm I've created.

Any help will be greatly appreciated, thank you !

Artur Meinild
  • 31,035
Nivlem
  • 565

7 Answers7

41

All you need is to add your user to the sudo group. There is no reason to modify the /etc/sudoers file.

su -
usermod -a -G sudo vboxuser

Then log out and back in for changes to take effect.

Terrance
  • 43,712
11

The simple answer to the question is:

In VirtualBox, when you are defining the iso location, there is a 'Skip Unattended Installation' box. It is unchecked by default.

Press it.

Then you go through the whole iso setup manually, from the 'Try Ubuntu / Install Ubuntu choice.

For some reason, even though the ubuntu user setup page looks exactly the same in both instances, only in the manual setup does the user get sudo privileges.

Took several installs to figure that out.

8

Use su - to become root, then nano /etc/sudoers. In order to add permissions to your user (here vboxuser), add the line vboxuser ALL=(ALL:ALL) ALL under root ALL=(ALL:ALL) ALL, save CTRL + O), exit the nano file (CTRL + X), and you're good!

cocomac
  • 3,824
Nivlem
  • 565
3

Today i've installed the same and i had the same issue.
I resolved this by a new installation without remarking unattended installation. In that case you have something more to do, but your user has sudoer rights.

A101755
  • 61
1

Well, I just installed Ubuntu 22.10 and had the same issue. However, it appears that the Ubuntu root password is set to the same value as the default account when I created the VM in Virtual Box. I just did "su", entered the default account password, and then modified the /etc/sudoers file in nano from there.

1

I'm teaching Sys Admin to my students and just ran into this issue. Here is what I will teach them.

  1. VirtualBox v7 has a new feature called "Unattended Installation". It is a nice automation which asks you up-front for all the info it needs during the install. It even installs the Guest-Additions for you.
  2. In VBox v6, we only had a manual install; so we answered questions (timezone, userid, etc.) during the install process. We installed GA manually.
  3. Important note: the v7 "Unattended Installation" has a quirky "feature" -- it does not put your initial userid into sudo group #27. In previous manual installations, the initial userid was a sudoer. So, this v7 "unattended installation" feels weird to me.
  4. To address this problem, the v7 "unattended installation" process sets the root (uid=0) password to the same password as the initial id (uid=1000). I don't really like this. I much prefer the linux "no password for root" rule.
  5. If you do use the v7 "unattended installation" process, then just become root with $ su - and use your initial pw. Then make your inital id (uid=1000) a sudoer. My favorite method is to just $ nano /etc/group and add your new id (uid=1000) to the sudo group (gid=27) line.
  6. In Vbox v7, the "unattended installation" is default. I like it - except for the sudoer and root pw quirk. I plan to have my students not use that default method; rather, to select "Skip Unattended Installation" and then manually install their favorite Ubuntu flavor guest OS in Vbox v7.
1
  1. Switch to the root user:

    su -
    
  2. Edit the sudoers file using the visudo command:

    visudo
    
  3. In the sudoers file, locate the line that looks like:

    %sudo   ALL=(ALL:ALL) ALL
    
  4. Below that line, add the following line to allow the user "your_username" to use sudo:

    your_username   ALL=(ALL:ALL) ALL
    
  5. Save and exit the sudoers file. (Ctrlx) If you are using the visudo command, it will prompt you to save the changes before exiting.

zx485
  • 2,865