22

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
  • 26,018
Nivlem
  • 455

7 Answers7

27

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
  • 41,612
  • 7
  • 124
  • 183
10

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.

  • Thank you so much. I remember the first time I used VirtualBox the tutorial I was following told me to do this but after a while I forgot (so when I was reinstalling it now I didn't know what to do). Thank you so much again. – iceninja21 Jun 27 '23 at 13:27
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,394
Nivlem
  • 455
  • How did you become root using su, if you don't know the password for it? – muru Nov 11 '22 at 06:23
  • There was no password promp. There was when I used su alone, though. Can't say I understand any of this. Do you know what the - after su does ? – Nivlem Nov 11 '22 at 15:29
  • That is incredibly surprising. su prompts for the root password if root has a password set. Recovery mode prompts for the password if root has a password set. If only one does but not the other, then there's been some significant reconfiguring going on in your VMs. Since you mention a colleague. are these VMs based on some company-built custom image? – muru Nov 11 '22 at 15:36
  • I got the image on the ubuntu website. I really don't understand where I messed up and why no one has had the same issuer, as everything I did really felt like the standard way a newbie would do it – Nivlem Nov 11 '22 at 15:43
  • @muru if you using live bootable OS or virtual device system don't ask for root password its by default empty. whatever u try sudo -s or su. in this case you have also rights of editing your current installed OS files you can do anything.. – Jason0011 Jan 02 '23 at 18:05
  • @Jason0011 ok, but this isn't about live systems. – muru Jan 03 '23 at 07:53
  • @Nivlem interesting, I just had this exact same problem, was trying su - and it did ask for for a password, but it was the password for my normal user account. The unattended install definitely needs to get this straightened out. – Kurt E. Clothier Jan 11 '23 at 19:25
  • Form me password for superuser was the same as password for user vboxuser: changeme – Ondřej Stašek Nov 26 '23 at 16:20
2

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
  • 41
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.
0
  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,426