Page 1 of 1

sudo -u username vboxmanage - global settings dir not accessible

Posted: 27. Mar 2018, 13:03
by mongole
Hi,
I have set up a Ubuntu 16.04 host with a 16.04 client, which has it's disks as LVM partitions. I encrypted them and I wrote a script to start the VM and to enter the decryption password. This works fine, as log as I am calling the script as the main user. As the systemd service handling is run as root, I need to be able to run the script as root.

But when I call the script as root with sudo, I get following error:

Code: Select all

VBoxManage: error: Failed to initialize COM because the global settings directory '/root/.config/VirtualBox' is not accessible!
The directory exists, and there are a lot of files and logfiles in there.

Of course I tried to start it as the main user with sudo, it fails with the same error:

Code: Select all

sudo -u andi bash -c "cd /home/andi/opt/VBoxManage; ./start-encrypted-vm.sh"
Error:

Code: Select all

...
VBoxManage: error: Failed to initialize COM because the global settings directory '/root/.config/VirtualBox' is not accessible!
...
It seems the VBoxManage is still run as root, why else would it like to access the /root/.config/VirtualBox directory and not the also existing /home/andi/.config/VirtualBox directory?

Re: sudo -u username vboxmanage - global settings dir not accessible

Posted: 15. Oct 2019, 05:18
by mebarton
The problem is not vboxmanage but the sudo env i.e. $HOME is still set to /root. I had the same problem with ubuntu MATE 18.04.

The following should work it did for me.

Code: Select all

export HOME="home/andi"
sudo -u andi bash -c "cd /home/andi/opt/VBoxManage; ./start-encrypted-vm.sh"
export HOME="root"
or you can play about with visudo and change "Defaults env_reset" and it options.
Read the man page before doing this as some company admins will have a problem with this being changed.