6

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.

11
  • 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.
    – popey
    Apr 6, 2023 at 8:44
  • 1
    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 ... 🤔
    – matigo
    Apr 6, 2023 at 8:45
  • @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
    Apr 6, 2023 at 8:52
  • 1
    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.
    – popey
    Apr 6, 2023 at 9:48
  • 1
    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.
    – popey
    Apr 6, 2023 at 9:48

2 Answers 2

4

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 ...

3
  • Thanks. It workds except two small differences. I have edited the answer accordingly.
    – Ron Gu
    Apr 6, 2023 at 9:46
  • @Ron Gu You are welcome Apr 6, 2023 at 10:05
  • pressing Shift at the beginning is tricky
    – knocte
    Jan 30 at 10:01
2

I am new to forums so I hope that Ron can see this if it is closed.

I'm not a avid VBox user and stumbled onto this answer using VBox on a Windows machine to create a live Arch system. Virtual Box DOES NOT indicate that it is doing this but whatever password is set for the initial user, - this is also the password for the root account. And yes Ron you are correct, it does not put the user account that you create, on install, in the sudoers file.

So if you don't touch the user account User: vboxuser; Password: changeme

the root pass will also be changeme

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .