Can I modify the ownership for a shared folder in vagrant?

vagrant shared folder mac
vagrant-libvirt shared folder
vagrant-vmware shared folder
vagrant share home directory
vagrant mount home folder
vagrant workspace
vagrant sync folder exclude
vagrant synced folder multiple

I use vagrant and chef to develop my own blog in a virtual machine. To have easy access to the wordpress folder I created a shared folder.

Basically the wordpress folder is on my host and gets mounted as shared folder in /var/www/wordpress in the VM. The configuration is similar to:

config.vm.share_folder "foo", "/guest/path", "/host/path"

My problem is that the ownership in my VM is always vagrant:vagrant even if I change it on my host. Ownership changes in the VM get ignored.

I cannot use chown to set the ownership of the upload directory to www-data:www-data.

It is possible to use chmod and change the access restrictions to 777, but this is a really ugly hack.

Here is what I actually want. Is this possible?:

  • Development: Access to the shared folder from my host.
  • Access Restriction: On the VM all files and folders should have proper and secure ownership and access restrictions.

As @StephenKing suggests you can change the options of the whole directory.

The relevant function is not documented but the source tells us:

# File 'lib/vagrant/config/vm.rb', line 53

def share_folder(name, guestpath, hostpath, opts=nil)
  @shared_folders[name] = {
    :guestpath => guestpath.to_s,
    :hostpath => hostpath.to_s,
    :create => false,
    :owner => nil,
    :group => nil,
    :nfs   => false,
    :transient => false,
    :extra => nil
  }.merge(opts || {})

Basically you can set group, owner and acl for the whole folder which is way better than setting everything to world writable on the host. I have not found any method to change the ownership of a nested directory.

Here is a quickfix:

config.vm.share_folder "v-wordpress", "/var/www/wordpress", "/host/path", :owner => "www-data", :group => "www-data"

Basic Usage, The second parameter must be an absolute path of where to share the folder within the guest Some synced folder types do not support modifying the owner. config. vm. synced_folder ".", "/vagrant", disabled: true » Modifying the Owner/Group. Sometimes it is preferable to mount folders with a different owner/group than the default SSH user. Keep in mind that these options will only affect the synced folder itself. If you want to modify the owner/group of the synced folder's parent folders use a


in 1.2+

config.vm.synced_folder "src/", "/srv/website",
  owner: "root", group: "root"

Synced Folders, By default, Vagrant will share your project directory (the directory with the Vagrantfile) to /vagrant . Read the basic usage page to get started with synced folders. Access Restriction: On the VM all files and folders should have proper and secure ownership and access restrictions. ayckoster As @StephenKing suggests you can change the options of the whole directory.

You can allow changing the ownership inside the guest:

config.vm.share_folder "foo", "/guest/path", "/host/path", {:extra => 'dmode=777,fmode=777'}

Changing shared folder permissions from within virtual machine , I would like to change the shared folder permissions from within the one who has to run vagrant reload because everyone else will start with  By default, the ".vagrant/" directory is excluded. We recommend excluding revision control directories such as ".git/" as well. rsync__rsync_ownership (boolean) - If true, and rsync executables in use are >= 3.1.0, then rsync will be used to set the owner and group instead of a separate call to modify ownership. By default, this is false.

Following up on @StephenKing and @aycokoster awesome tips, I had a use-case for mounting another directory read-only.

I added

config.vm.share_folder "foo", "/guest/path", "/host/path", :extra => 'ro'


# discard exit status because chown `id -u vagrant`:`id -g vagrant` /host/path is okay

vagrant up || true 

Unable to set permissions within shared folder using Vagrant and , Unable to set permissions within shared folder using Vagrant and to modify files, albeit very generously, since it can modify much more than it  Synced folders enable Vagrant to sync a folder on the host machine to the guest machine, allowing you to continue working on your project's files on your host machine, but use the resources in the guest machine to compile or run your project. By default, Vagrant will share your project directory (the directory with the Vagrantfile) to /vagrant.

As the other answers have pointed out you should probably set the correct owner and group using the owner and group configuration options.

However, sometimes that won't work (for example when the target user is only created later on during provision). In these cases, you can remount the share:

sudo mount -t vboxsf -o uid=`id -u www-data`,gid=`id -g www-data` /path/to/share /path/to/share

Changing folder permissions on a certain folder in vagrant synced , I have set the folder permissions of my synced folder in the vagrant file as running vboxmanage share + mount on the guest wirthout vagrant you will probably  Take ownership of a file or folder To start the change of ownership process, activate Windows File Explorer and navigate to the specific file or folder to be changed. Right-click that file and then

Folder Syncing (vm.synced_folder): How to code with and change , For example, the actual file permissions of your folders conflicting with the actual file permissions of the boxes. I always do: config.vm.synced_folder ".", "/var/www​  You must ensure the /vagrant/vagrant_data directory is empty on the guest machine. Then you can run vagrant reload which will restart the guest and mount the directory. Once the directory is mounted, you can add files in the guest or on the host and you will see them in both places. Cheers!

How to change group id and mountpoint of vagrant default shared , Owner and group of the directory is vagrant . How can I change the mount point and the group id of the default share? Maybe I'm blind but I didn't found anything​  1. Ok so to change ownership of your drives, folders or files, do this: First go to network & sharing and if you are joined to the Home Group, stop sharing files and devices. Then UNJOIN IT. (For Drives and Folders Ownership). NOTE: It is useless and being discontinued in the next creators pack or soon after.

Sharing Files Between Your Guest and Host Machines, Typically when we work with a Web server, we edit our files locally, and then "​push" The same will be true with our Vagrant server: you need a way to get files from If you are having problems with file permissions / ownership, try editing the  The developer of Vagrant has answered the question on Github: This is correct. it doesn't change the owner, it just changes the user that files are read/written as when they are accessed on the guest. You won't see any visible change in the guest.

  • Any idea how to do this with vagrant 1.2+? I believe the relevant file (for Virtualbox) is now plugins/providers/virtualbox/action/share_folders.rb.
  • Multiple shared_folders on common intersecting directories seem to take into account the last definition. So for nested directories, you would simply add the directive (with owner: & group:) after
  • For NFS mounted drives, use config.vm.synced_folder
  • one thing worth noting is if you want to change permissions on the default synced_folder you need to use the syntax from this answer,, which is: config.vm.synced_folder "./", "/vagrant", owner: 'root', group: 'root'
  • using Vagrant 1.5.4, this approach didn't work for me. I added the above to my .kitchen.yml, modified my custom_app cookbook to call sudo chown -R kevin /my/path/share. Then I destroyed and provisioned my box again. yet vagrant still owns /my/path/share. Additionally, I tried the above command manually in the VM, yet the owner is still `vagrant.
  • Using 1.7.4 I need to change this to config.vm.synced_folder ..., {:mount_options => [dmode=777, fmode=777]
  • To make your vagrant box run a little bit more like a production server would, run dmode=775,fmode=664 instead of 777. Now when you deploy you should run into one less issue, because you're not depending on global write permissions.