17

I have set up a synced folder in Vagrant, from my Windows host to the guest. Initially the permissions on the files were too open so I added the following mount options:

config.vm.synced_folder "../my-folder", "/home/vagrant/my-folder",
    mount_options: ["dmode=775,fmode=664"]

However, I need to add execute permissions on a single file within this folder. chmod +x file has no effect. Is there a way to allow a single item in a shared folder to be executable/have different permissions to the rest of the items in the folder?

Andrew
  • 401
  • 1
  • 3
  • 10

2 Answers2

23

In the end, I came up with two solutions:

1) Accept all the files being executable

config.vm.synced_folder "../my-folder", "/home/vagrant/my-folder",
    mount_options: ["dmode=775,fmode=777"]

2) Use the rsync method to synchronise the folders

config.vm.synced_folder "../ansible-provision", "/home/vagrant/ansible", type: "rsync",
    rsync__exclude: ".git/"

Each method has its own drawbacks, but the first was quickest to implement and acceptable for my use case, so I went with that.

Andrew
  • 401
  • 1
  • 3
  • 10
4

I was having a similar issue with folder permissions. I'm using virtualbox on Mac OSX. I added the owner and group options which fixed my issue of not being able to write to a cache directory on the server. Update to include folder and file modes.

srv.vm.synced_folder server["synced_folder"]["src"], server["synced_folder"]["dest"], create: true, group:'vagrant', owner:'www-data', mount_options: ["dmode=775,fmode=664"]
jtaz
  • 119
  • 3
  • This solution may not work for a new initialization of vagrant because the custom user and/or group may not exist in the box. – MingalevME Feb 22 '18 at 20:14
  • @MingalevME I'm doing this for the Apache user and group (www-data) on Ubuntu, before Apache is installed, and it works fine. See: https://unix.stackexchange.com/questions/305170/is-it-ok-to-have-files-owned-by-a-non-existent-user – Felipe Zavan May 20 '20 at 15:49
  • 2
    Could a different approach be to add the www-data user to group vagrant in your provisioning script? That way owner user and group could remain vagrant but user www-data would still have vagrant's permissions. Just a thought... – Kalle Sep 29 '20 at 13:23