New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing shared folder permissions from within virtual machine #897

Closed
axsuul opened this Issue Apr 25, 2012 · 10 comments

Comments

Projects
None yet
9 participants
@axsuul

axsuul commented Apr 25, 2012

I would like to change the shared folder permissions from within the virtual machine. So something like

chown some-random-user /vagrant

Doing this has no effect as the folder's owner as it remains to be vagrant. Is it possible?

@mitchellh

This comment has been minimized.

Show comment
Hide comment
@mitchellh

mitchellh Apr 25, 2012

Member

Yes, this doesn't work with VirtualBox shared folders. It is not a bug with Vagrant. Instead, you should set the :owner and/or :group option on the shared folder:

config.vm.share_folder "v-root", "/vagrant", ".", :owner => "foo"
Member

mitchellh commented Apr 25, 2012

Yes, this doesn't work with VirtualBox shared folders. It is not a bug with Vagrant. Instead, you should set the :owner and/or :group option on the shared folder:

config.vm.share_folder "v-root", "/vagrant", ".", :owner => "foo"

@mitchellh mitchellh closed this Apr 25, 2012

@axsuul

This comment has been minimized.

Show comment
Hide comment
@axsuul

axsuul Apr 25, 2012

Thanks Mitchell. It appears if I use the :group option, the command that is run appears to be

mount -t vboxsf -o uid=`id -u USERNAME`,gid=`id -g GROUPNAME` v-root /vagrant

On Ubuntu at least, id -g GROUPNAME doesn't return the proper gid. As a result, the folder fails to mount due to the above command failing.

Also, the :owner and :group options don't appear to be documented here: http://vagrantup.com/docs/config/vm/share_folder.html. Initially I was using :map_uid and :map_gid.

axsuul commented Apr 25, 2012

Thanks Mitchell. It appears if I use the :group option, the command that is run appears to be

mount -t vboxsf -o uid=`id -u USERNAME`,gid=`id -g GROUPNAME` v-root /vagrant

On Ubuntu at least, id -g GROUPNAME doesn't return the proper gid. As a result, the folder fails to mount due to the above command failing.

Also, the :owner and :group options don't appear to be documented here: http://vagrantup.com/docs/config/vm/share_folder.html. Initially I was using :map_uid and :map_gid.

@chrisvanpatten

This comment has been minimized.

Show comment
Hide comment
@chrisvanpatten

chrisvanpatten Aug 26, 2012

I have a similar problem: the command fails with :owner set, because at this point in the process the user I want to own the shared folder hasn't been provisioned into place yet.

Is there a workaround, other than to vagrant up without :owner and then run vagrant reload with it in place? Seems rather clunky.

I have a similar problem: the command fails with :owner set, because at this point in the process the user I want to own the shared folder hasn't been provisioned into place yet.

Is there a workaround, other than to vagrant up without :owner and then run vagrant reload with it in place? Seems rather clunky.

@markjaquith

This comment has been minimized.

Show comment
Hide comment
@markjaquith

markjaquith Sep 14, 2012

Contributor

@chrisvanpatten Another workaround is to update your basebox (I use veewee) so that the users and/or groups required are already in place. That worked for me when setting some www-data-writable directories. But that wouldn't work when the users/groups you're assigning change often.

Contributor

markjaquith commented Sep 14, 2012

@chrisvanpatten Another workaround is to update your basebox (I use veewee) so that the users and/or groups required are already in place. That worked for me when setting some www-data-writable directories. But that wouldn't work when the users/groups you're assigning change often.

@chrisvanpatten

This comment has been minimized.

Show comment
Hide comment
@chrisvanpatten

chrisvanpatten Sep 14, 2012

@markjaquith Unfortunately they change per project (we use individual groups per project/website) so setting that in the base box isn't a feasible option. Luckily reloading after the initial provision isn't too painful!

@markjaquith Unfortunately they change per project (we use individual groups per project/website) so setting that in the base box isn't a feasible option. Luckily reloading after the initial provision isn't too painful!

@ffa

This comment has been minimized.

Show comment
Hide comment
@ffa

ffa Oct 18, 2012

A middle ground is to run vagrant up without the chown settings, package the box, refer to creating a box at the bottom of http://vagrantup.com/v1/docs/boxes.html, and then distribute that as the initial box for the project. This avoids having to build a base box every time and provides a provisioned setup for the project lowering setup time. Also, this setup infers that the packager is the only one who has to run vagrant reload because everyone else will start with the packaged box.

ffa commented Oct 18, 2012

A middle ground is to run vagrant up without the chown settings, package the box, refer to creating a box at the bottom of http://vagrantup.com/v1/docs/boxes.html, and then distribute that as the initial box for the project. This avoids having to build a base box every time and provides a provisioned setup for the project lowering setup time. Also, this setup infers that the packager is the only one who has to run vagrant reload because everyone else will start with the packaged box.

@netmikey

This comment has been minimized.

Show comment
Hide comment
@netmikey

netmikey Oct 30, 2012

As an alternative solution, you might find this one interesting: http://serverfault.com/questions/398414/vagrant-set-default-share-permissions
The idea here would be to mount the folder group writable and add the webserver's www-data user to the vagrant group.

As an alternative solution, you might find this one interesting: http://serverfault.com/questions/398414/vagrant-set-default-share-permissions
The idea here would be to mount the folder group writable and add the webserver's www-data user to the vagrant group.

@akshayagarwal

This comment has been minimized.

Show comment
Hide comment
@majkinetor

This comment has been minimized.

Show comment
Hide comment
@majkinetor

majkinetor Nov 13, 2014

Is it possible to change permissions on individual files ?

Is it possible to change permissions on individual files ?

@widoz

This comment has been minimized.

Show comment
Hide comment
@widoz

widoz Dec 26, 2017

Sorry to open this again, but I encountered the same problem within WordPress installation.

Apache run with www-data:www-data perms, but within the Vagrantfile I'm not able to set the properly perms for directories.

These doesn't help.
I running Vagrant 2, you can see configuration and provisioners here https://github.com/widoz/vagrant-lamp

config.vm.synced_folder "/var/www/html/wp",
    owner: "www-data", group: "www-data",
    mount_options: ["dmode=755","fmode=644"]

config.vm.provision "shell" do |s|
    s.inline = "mount -t vboxsf -o uid=`id -u www-data`,gid=`id -g www-data`,dmode=755,fmode=644 /var/www/html/wp"
end

widoz commented Dec 26, 2017

Sorry to open this again, but I encountered the same problem within WordPress installation.

Apache run with www-data:www-data perms, but within the Vagrantfile I'm not able to set the properly perms for directories.

These doesn't help.
I running Vagrant 2, you can see configuration and provisioners here https://github.com/widoz/vagrant-lamp

config.vm.synced_folder "/var/www/html/wp",
    owner: "www-data", group: "www-data",
    mount_options: ["dmode=755","fmode=644"]

config.vm.provision "shell" do |s|
    s.inline = "mount -t vboxsf -o uid=`id -u www-data`,gid=`id -g www-data`,dmode=755,fmode=644 /var/www/html/wp"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment