Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant synced folder permissions

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?

like image 579
Andrew Avatar asked Mar 04 '16 22:03

Andrew


People also ask

Which directory in your Vagrant VM is the synchronized folder?

Vagrant automatically syncs files to and from the guest machine. This way you can edit files locally and run them in your virtual development environment. By default, Vagrant shares your project directory (the one containing the Vagrantfile) to the /vagrant directory in your guest machine.

What is Vagrant VM?

Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past.


2 Answers

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.

like image 68
Andrew Avatar answered Sep 28 '22 03:09

Andrew


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"]
like image 29
jtaz Avatar answered Sep 28 '22 03:09

jtaz