0

I have created a shared folder in /Users/shared_folder. I have moved the virtual box files to that folder /Users/shared_folder/.VirtualBox VMs/

I have set the whole folder with all the permissions: sudo chmod -R 777 shared_folder. I have switched to the other user, and I have executed the same command. I also have tried with the following command as I read here (without knowing what I was doing by the way): find somedir \( -type d -exec chmod u+rwx,g+rwx,o+rx {} \; -o -type f -exec chmod u+rw,g+rw,o+r {} \; \)

Both users can access the same virtual machine... Till some of them save the machine state. Then, the other user cannot access because of not enough reading permissions.

How could I share the same virtual machine with both users?

0

What is happening is that the files created, when the machine state is saved, are given the permissions based on the current user. Therefore, all other users will be disallowed from using these new files.

To fix it, you need to make sure all users are in the same group, and set additional bits on the folder, which will cause all children folders/files inherit the same permissions.

(1) Create a Group for users to share:

Add a group, e.g.:

sudo groupadd vboxsharing

(Note, there is a "vboxusers" group already installed by VirtualBox. It has a specific use, but you can user this existing group rather than adding a new one.)

(2) Add users to the group:

The users who will need access to the shared VMs, need to be added to the group:

sudo usermod -a -G vboxsharing <user1>
sudo usermod -a -G vboxsharing <user2>
# ... etc.

NOTE: You can alternatively set the group as primary for all these users (sudo usermod -g vboxsharing <userXYZ>), which means you can skip step #3 below. However, doing so is a security risk and should be avoided.

(3) New VirtualBox files to be accessible to the group:

Change the folder's group ownership:

sudo chgrp -R vboxsharing /Users/shared_folder

And, set bits setuid and setgid, as necessary, to ensure future files are created for the group.

Therefore, for your folder, do the following:

sudo chmod -R 6770 /Users/shared_folder

The 6, at the start of the permission bits, is the combination of setuid and setgid:

  • setuid = 4
  • setgid = 2

Technically, you DO NOT need setuid. Therefore, it is enough to have:

sudo chmod -R 2770 /Users/shared_folder

..

Note:
And, you don't need that long find command, it is a command to apply a different set of permissions to files, and a different set to folders.

3
  • Thank you man. Unfortunately, the same problem still occurs: VirtualBox still set permissions to the current user only. I'm thinking in the workaround of a script that changes the permissions right before executing VirtualBox. It would be ugly and the users will have to introduce their admin passwords every time though...
    – chelder
    Jul 3 '16 at 13:30
  • 1
    If you SETGID the folders and everyone has group write (via umask) then the owners of the files won't matter.
    – chicks
    Jul 4 '16 at 13:04
  • @chicks, thanks for pointing out the redundancy. I've modified my answer, to highlight the unnecessary setting of setuid, and expand to ensure group is set (I may have incorrectly assumed that it is obvious). I will experiment later today when I have some time, to make sure my answer works on my machine... so apologies, my answer may still be incorrect.
    – jehad
    Jul 4 '16 at 13:47
0

The previous solutions did not work for me.

I have finally decided to create a different virtualbox hard disk for each user.

Another approach could be to create a script that checks if the folder is owned by the current user. If it is not, change the permissions before opening VirtualBox.

I have wrote about both approach here: https://askubuntu.com/a/820614/279148

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.