I am using Ubuntu on Virtual Box and I have a folder which is shared between the host (Windows) and the VM (Ubuntu). When I open any file in the share folder in Ubuntu, I can not change it as its owner is set to root.

How can I change the ownership to myself?

Here is the output of ls -l :

-rwxrwxrwx 1 root root 0 2012-10-05 19:17 BuildNotes.txt

The output of df is:

m@m-Linux:~/Desktop/vbox_shared$ df
Filesystem   1K-blocks      Used Available Use% Mounted on
/dev/sda1     29640780  10209652  17925440  37% /
none            509032       260    508772   1% /dev
none            513252       168    513084   1% /dev/shm
none            513252        88    513164   1% /var/run
none            513252         0    513252   0% /var/lock
none            513252         0    513252   0% /lib/init/rw
Ubuntu       214153212  31893804 182259408  15% /media/sf_Ubuntu
/dev/sr0         53914     53914         0 100% /media/VBOXADDITIONS_4.2.0_80737
Ubuntu       214153212  31893804 182259408  15% /home/m/Desktop/vbox_shared

The options in VM is automount and the readoly is not checked.

Tried to use /media/sf_Ubuntu, but getting permission error:

m@m-Linux:/media$ ls -l 
total 10
drwxrwx--- 1 root vboxsf 4096 2012-10-23 15:35 sf_Ubuntu
drwxrwx--- 2 root vboxsf 4096 2012-10-21 23:41 sf_vbox_shared
dr-xr-xr-x 6 m    m      2048 2012-09-13 07:19 VBOXADDITIONS_4.2.0_80737
m@m-Linux:/media$ cd sf_Ubuntu/
bash: cd: sf_Ubuntu/: Permission denied
m@m-Linux:/media$ cd sf_vbox_shared/
bash: cd: sf_vbox_shared/: Permission denied

Please note that I am in the group vboxsf:

m@m-Linux:~$ id
uid=1000(m) gid=1000(m) groups=4(adm),20(dialout),24(cdrom),46(plugdev),105(lpadmin),119(admin),122(sambashare),1000(m),1001(vboxsf)
  • How did you mount the shared folder? Are you letting it be automounted by the VirtualBox guest utils (i.e. /media/sf_something) or did you mount it manually using the mount command? – EightBitTony Oct 23 '12 at 14:45
  • Also, can you describe how you have configured the share under VirtualBox in Windows? There are three options for the share, read only, automount and permanent, which options have you ticked. – EightBitTony Oct 23 '12 at 14:48
  • Please post updates to your question - not as comments. Please include the output of df and the command you used to manually mount the filesystem. – EightBitTony Oct 23 '12 at 14:53
  • Thank you - you will see there is a /media/sf_Ubuntu filesystem. That's your shared folder, you don't need to manually mount it. I suggest you umount the /home/m/Desktop thing, and just use /media/sf_Ubuntu which works as per my answer below. – EightBitTony Oct 23 '12 at 14:57
  • @Tony: I can not access this folder. Please see my original question which I add more information – user654019 Oct 23 '12 at 15:26
up vote 141 down vote accepted

The regular way of getting access to the files now, is to allow VirtualBox to automount the shared folder (which will make it show up under /media/sf_directory_name) and then to add your regular Ubuntu user to the vboxsf group (as root #).

# usermod -aG vboxsf <youruser>

By default, without manual action, the mounts look like this,

drwxrwx--- 1 root vboxsf 40960 Oct 23 10:42 sf_<name>

so the vboxsf group has full access. By adding your user to that group, you gain full access. So you wouldn't worry about changing their permissions (which don't make sense on the Windows host), you just give yourself access.

In this specific case, this is the automounted Shared Folder,

Ubuntu               214153212  31893804 182259408  15% /media/sf_Ubuntu

and it is that directory that should be used to access to the Shared Folder, by putting the local user into the vboxsf group. If you want a 'better' link under your user's home directory, you could always create a symbolic link.

ln -s /media/sf_Ubuntu /home/m/Desktop/vbox_shared

You will need to reboot your VM for these changes to take effect

If you manually mount the shared folder, then you need to use the relevant options on the mount command to set the folder with the right ownership (i.e. the gid, uid and umask options to mount). This is because the Host OS doesn't support the same permission system as Linux, so VirtualBox has no way of knowing who should own the files.

However, I strongly recommend just configuring the shared folder to be auto-mounted (it's a setting on the Shared Folder configuration in VirtualBox itself).


For the avoidance of doubt, I do not believe you can change permissions normally anyway, on that filesystem if it's mounted in the regular way,

tony@jabba:/media/sf_name$ ls -l tst.txt
-rwxrwx--- 1 root vboxsf 2283 Apr  4  2012 tst.txt
tony@jabba:/media/sf_name$ sudo chown tony tst.txt
[sudo] password for tony: 
tony@jabba:/media/sf_name$ ls -l tst.txt
-rwxrwx--- 1 root vboxsf 2283 Apr  4  2012 tst.txt
tony@jabba:/media/sf_name$ 
  • 2
    When I tried this, I got the message that user is lready in group, but when I am trying to change a file on share folder, I am getting error when I want to save it. The error is: Could not save the file /home/m/Desktop/vbox_shared/test.tst Unexpected error: error renaming temporary file: Text file busy. – user654019 Oct 23 '12 at 14:40
  • That's a different problem, potentially not due to permissions. Can you create a new file, or modify a different file. Hang on - /home/m/Desktop/vbox_shared? Have you manually mounted the shared folder? That's not the default path. – EightBitTony Oct 23 '12 at 14:41
  • Checking system, I found that I only have permission to create or delete files and not read/write permision. How can I give it to myself? – user654019 Oct 23 '12 at 14:43
  • 7
    Seems reboot is needed to make it take effect. – Eric Wang Oct 30 '15 at 17:17
  • 3
    YOU DESERVE A BEER FOR THIS ANSWER!!! I couldn't get this to work at all until I came across this. Can't believe this isn't out there more. I wish I could upvote it more than once!! – Tensigh Oct 19 '16 at 4:51

I had the same problem and I solved installing the latest version of VirtualBox Guest Additions; in my case was upgrading from 4.3.8 to 4.3.10.

When installation was finished, the /media/sf_name folder had no more "root" as group owner, but "vboxsf" as correct.

I just have had the same problem with my Win-Ubuntu shared folder, and the way I solved it was adding my user into the vboxsf group, editing the /etc/group file. Hope this works for you. Down here you can find a short scheme of how I edited the file

(edit /etc/group)
...
...
...
pulse:x:119:
pulse-access:x:120:
utempter:x:121:
rtkit:x:122:
saned:x:123:
openquake:x:1000:
sambashare:x:124:openquake,luisa
vboxsf:x:999:openquake,luisa   ##This is the line I add my user
postgres:x:125:
rabbitmq:x:126:
celery:x:500:
luisa:x:1001:

Luisa.

  • 1
    You should never edit /etc/group directly, use the appropriate tools for this job (in this case usermod -aG <group> <user>). – raimue Nov 5 '15 at 0:18
  • The main, if not only, reason why this is recommended is because if you accidentally make a mistake manually updating a file like /etc/group, it can invalidate the DB and essentially lock you out. – Spencer Williams Nov 12 '15 at 20:07

Have you tried sudo?

$sudo chown username filename
  • I don't believe this works on VirtualBox shared folders. – EightBitTony Oct 23 '12 at 12:43
  • sudo works everywhere! :P link – Extn3389 Oct 23 '12 at 12:46
  • 12
    I'm not sure if you're serious, but I'll humour you. The mounted shared folder is a vboxfs type filesystem, it does not honour chown's. – EightBitTony Oct 23 '12 at 12:47
  • I am sorry I just thought this might work. – Extn3389 Oct 23 '12 at 13:18
  • 1
    Yes, but it did not change the owner. After running tis command in a terminal for a file, and then looking at the file owner, it still belongs to root. – user654019 Oct 23 '12 at 13:41

If you have the luxury of controlling the options to the mount command (for instance if mounting manually or using /etc/fstab) you can use the -o uid=771 option to the mount commmand.

An entry in /etc/fstab would look like

scanresults    /data/scanresults    vboxsf    uid=771    0 0

Enable full read,write access to a shared folder on a Windows host from an Ubuntu guest for a non-root Linux user

This step will enable you to access a certain dir on your Windows host machine from the Linux guest terminal. In this example the name of the share from the OVB perspective will be vshare ( which is the default ) , the full dir path to the Windows OS ( the host OS ) will be "C:\var\" and the full file path to access it from the guest vm will be "/vagrant", and finally the name of the user to enable the full rea/write access will be "you".

 # how-to add a shared folder on the host
 VBoxManage sharedfolder add "host-name" -name "vshare" -hostpath "C:\var" -automount

1. Install the Guest Additions prerequisites

Install the Guest Additions prerequisites by issuing the following command:

 sudo apt-get install -y build-essential make gcc  linux-headers-$(uname -r) 
 linux-headers-generic make linux-source  linux-generic linux-signed-generic

2. Install the Guest Additions

Do not use the .iso file to download and the installer from there - it will simply not work !!!

sudo apt-get install virtualbox-guest-dkms 

3. Change your for the share dir to be automounted on vm boot

Change your for the share dir to be automounted on vm boot by addding the folowing lines to the end of your fstab file ( note the "vshare" conf , and the uid=10001 ):

/media/sf_vshare /vagrant vboxsf bind,uid=10001,rw,umask=0000 0 0
# eof file: /etc/fstab 

4. add yourself to the vboxsf group

You need to add yourself to the vboxsf group in order to be able to edit as non-root from your vm the files on your host machine. # mount sudo mount -a

sudo usermod -G vboxsf -a you 

5. reboot and verify

Reboot the vm and login via ssh to verify the file sharing. # ssh to the vm ssh you@host-name

# check as yourself that you have 
find /vagrant

Virtual box additions have to be installed again after you upgrade your guest system. The problem, I think, is when you upgrading some components in ubuntu, some components changed, after installing vb-additions, sf_forlder_name will be accessible. My problem solved by this way. Pisu's solution works.

  • In my experience virtual box guest additions only have to be upgraded when the host VirtualBox system is upgraded. Not when any software on the client changes. What software on the client did you upgrade to make this necessary? – Anthon May 18 '14 at 7:13
  • No, nicky is right. You have to re-install the Guest Additions if you update your guest OS kernel. – Spencer Williams Nov 12 '15 at 20:08
  • Unmount shares as root
  • Make required changes with chown and chmod
  • reboot and checkout the shares are with proper rights

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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