140

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)
7
  • 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? Commented Oct 23, 2012 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. Commented Oct 23, 2012 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. Commented Oct 23, 2012 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. Commented Oct 23, 2012 at 14:57
  • @Tony: I can not access this folder. Please see my original question which I add more information
    – user654019
    Commented Oct 23, 2012 at 15:26

10 Answers 10

205

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$ 
20
  • 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
    Commented Oct 23, 2012 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. Commented Oct 23, 2012 at 14:41
  • 11
    Seems reboot is needed to make it take effect.
    – Eric
    Commented Oct 30, 2015 at 17:17
  • 7
    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
    Commented Oct 19, 2016 at 4:51
  • 1
    I've created an account on Stack Exchange just to say thank you, saved my day Commented Apr 13, 2020 at 14:31
6

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 directory 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 directory 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". Finally, the name of the user to enable the full read/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 run the installer from there - it will simply not work !!!

sudo apt-get install virtualbox-guest-dkms 

3. Automount the Share on Boot

Configure the share directory to be automounted on vm boot by adding the following lines to the end of your /etc/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

# 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 access
find /vagrant
3

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.

2
  • 2
    You should never edit /etc/group directly, use the appropriate tools for this job (in this case usermod -aG <group> <user>).
    – raimue
    Commented Nov 5, 2015 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. Commented Nov 12, 2015 at 20:07
2

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.

1

Have you tried sudo?

$sudo chown username filename
5
  • 2
    I don't believe this works on VirtualBox shared folders. Commented Oct 23, 2012 at 12:43
  • sudo works everywhere! :P link
    – Extn3389
    Commented Oct 23, 2012 at 12:46
  • 14
    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. Commented Oct 23, 2012 at 12:47
  • I am sorry I just thought this might work.
    – Extn3389
    Commented Oct 23, 2012 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
    Commented Oct 23, 2012 at 13:41
1

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
0

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.

2
  • 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
    Commented May 18, 2014 at 7:13
  • 1
    No, nicky is right. You have to re-install the Guest Additions if you update your guest OS kernel. Commented Nov 12, 2015 at 20:08
0

In my case it did not resolve to add myself to the vboxsf directory. I finally find out that the path to the auto-mounted directory was the problem :

/mnt/host/sf_win

Only /mnt was existing on the guest. But the mount did actually work, and with the permission for the group. But no operation was allowed without sudoing.

Modifying the mount point to /mnt/sf_win resolved my issue.

0

As discussed in this post, the problem with vboxsf automounts like /media/sf_Ubuntu is that

You will find permission issues using the automount feature as they are handled differently in removable media by the OS.

and solution is to

Remove the automount and use a standard mount instead with the options flag and set you required permissions there.

That is, you can mount the shared folder to a location (e.g. /Ubuntu) while using appropriate options to set the uid and gid of the mount to your unix user (from your id results).

sudo mount -t vboxsf -o rw,uid=1000,gid=1000 Ubuntu /Ubuntu

, or equivalently, you can add an entry as follows in /etc/fstab:

Ubuntu    /Ubuntu    vboxsf  rw,uid=1000,gid=1000   0 0

This way, the mounted folder will be under your Ubuntu user name/group.

-2
  • Unmount shares as root
  • Make required changes with chown and chmod
  • reboot and checkout the shares are with proper rights

You must log in to answer this question.

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