Score:14

VirtualBox Ubuntu 22.04: how to add sudo rights?

bi flag

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 !

in flag
I’m a little confused about what you’re trying to do and what error you’re getting. Could you [edit] your question to include an example command with `sudo` that is failing and the exact error? As for the password, you use *your* account password, not a different one.
Artur Meinild avatar
vn flag
Does this answer your question? [How can I add a user as a new sudoer using the command line?](https://askubuntu.com/questions/7477/how-can-i-add-a-user-as-a-new-sudoer-using-the-command-line)
za flag
Didn't you chose a username/password on installation but use "unattended installation"?
karel avatar
sa flag
Does this answer your question? [Default Password in Ubuntu 15.04](https://askubuntu.com/questions/624324/default-password-in-ubuntu-15-04)
za flag
@matigo, @karel: With VirtualBox 7, the installation process has changed drastically and depending on your choices, you end in a situation like this. You can do `su -` but not `sudo -i`, for instance.
cn flag
related: [How can I make my own account a sudoers on VirtualBox?](https://superuser.com/questions/1623376/how-can-i-make-my-own-account-a-sudoers-on-virtualbox)
Score:13
id flag

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.

SagarPPanchal avatar
fr flag
+1 Perfect answer!!! Made my Day :)
Score:7
cn flag

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.

iceninja21 avatar
xk flag
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.
Score:4
bi flag

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!

muru avatar
us flag
How did you become root using `su`, if you don't know the password for it?
Nivlem avatar
bi flag
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 ?
muru avatar
us flag
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?
Nivlem avatar
bi flag
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
guenon avatar
by flag
@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**..
muru avatar
us flag
@Jason0011 ok, but this isn't about live systems.
Kurt E. Clothier avatar
ly flag
@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.
Score:2
kh flag

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.

Nivlem avatar
bi flag
I'm pretty sure I didn't tick that box
Score:0
us flag

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.
Score:0
ag flag

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.

Organic Marble avatar
us flag
Consider using the safer `visudo` for this task.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.