Score:0

Installing Ubuntu 22.04 in VirtualBox causes the account to be not a sudoer nor a root user

cc flag

I have just installed Ubuntu 22.04 in my VirtualBox and created only one account, say "A". Although A is the only user in the system, it is not in the sudoers file because when I run "sudo passwd root", it shows that A is not in the sudoers file. However, to add A into the sudoers file, I must be a root user, which turns me back to the initial question: sudo passwd root.

Does anyone know how to solve this loop? Thanks a lot!

Experience: do not use the unattended installation provided by VirtualBox. It adds a vboxsf user, which is the cause of this problem.

pl flag
How did you install Ubuntu in the VM? Is this a pre-made VM or did you download an official ISO and install onto a virtual hard disk? The reason I ask is during the official installer it will ask you for a username and password for a user which *will* be an admin/root privileges account. Accounts you create after that aren't, but the first one will be.
in flag
This is probably a silly question, but why are you trying to set the password for `root`? This is unnecessary in most modern Linux distributions ...
Ron Gu avatar
cc flag
@popey I installed Ubuntu by using the official ISO of 22.04 LTS. VirtualBox did ask me for setting the username and password, which is the "A" account that I mentioned in the question.
Ron Gu avatar
cc flag
@matigo I wanted to use sudo, but it says that my account is not in the sudoers file. So I need to log in as a root to add my account to the file, which leads to my problem.
Ron Gu avatar
cc flag
FYI, I simply followed the default installing steps of 22.04 in VirtualBox, and created an account and its password during the installation. I use VirtualBox to run my Ubuntu 20.04 LTS for quite a while and it runs well. However, installing 22.04 in VirtualBox 7.0 gives such a trouble.
pl flag
What is the output of the commands `id` and `groups`? Please paste in your question above. Also `ls /home`
Ron Gu avatar
cc flag
@popey I added my answer to the question above.
pl flag
In VirtualBox there's a "Skip Unattended Installation" option which is unticked by default. Did you tick that? Because by default it looks like it creates a "vboxuser" account. Seems like it's bypassing the Ubuntu defaults with that.
Ron Gu avatar
cc flag
Thanks @popey, I used the unattended installation. I also suspect that causes the problem. The problem is solved now. Please see the answer below. Thank you anyway.
pl flag
Ok, I just did an install of Ubuntu using VirtualBox. It has its own automated installer. This is totally a VirtualBox issue and not an Ubuntu one. The Ubuntu installer, when used correctly does NOT do this.
pl flag
I’m voting to close this question because this is not a problem with Ubuntu. The VirtualBox assistant is breaking the default behaviour of the Ubuntu installer, by not making the first user a sudo user.
Score:0
hm flag

Power on or reboot your system, press Shift until you see the grub menu list then select recovery mode.

Drop to root shell prompt. (root)

If it asks password, use the password of the account that is going to be added to the sudoers file.

Run this command:

# usermod -a -G sudo yourusername

Where yourusername is ron for ex ...

Reboot the system

After reboot and logged in you can run commands with sudo. ex:

$ sudo apt update

It's not recommended to enable/login with root account, by setting root user a password it's account gets enabled automatically.

By default you can run any sudo command as root permissions without the need of enable/login as root ...

Ron Gu avatar
cc flag
Thanks. It workds except two small differences. I have edited the answer accordingly.
Luiz Carlos avatar
hm flag
@Ron Gu You are welcome
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.