The other answers are correct, in that chmod -R 755
will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?
I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find
command. For example:
To change all the directories to 755 (drwxr-xr-x
):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--
):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
Some splainin': (thanks @tobbez)
chmod 755 {}
specifies the command that will be executed by find
for each directory
chmod 644 {}
specifies the command that will be executed by find
for each file
{}
is replaced by the path
;
the semicolon tells find
that this is the end of the command it's supposed to execute
\;
the semicolon is escaped, otherwise it would be interpreted by the shell instead of find
There are several partial answers here, but I'd like to make it much easier for people finding this question, so that they do not have to experiment with various ways of combining those partial answers into one.
This is what I use, and it is working well for me. Since it's difficult or impossible to use italics inside a <code>
block, I've put the bits you'll want to change inside <angled brackets>
.
config.vm.synced_folder ".", "/var/www/vhosts/<project_name>",
id: "project",
owner: <username>,
group: <group_name>,
mount_options: ["dmode=775,fmode=664"]
Or possibly (depending on the version of CIFS/SMB you're using):
mount_options: ["dir_mode=775,file_mode=664"]
Without the owner and group, Vagrant will use the value of config.ssh.username
(when the box was booted) as the owner and group. By using a configuration like the one above, you can control what owner and group are assigned to the shared folder, since logging into the VM and trying to use chgrp
and chown
does not work.
Without the mount_options
, you'll have no way to control what rights are given to the owner and group (and others). Even though this is a VM, and you could argue that it's okay to use 777
rights for these, I don't recommend it since it's a bad habit, and if you're not careful you're liable to carry it over into production, weakening your production security. But obviously you can change the 775
and 664
that I used to whatever you want. If you don't know what those mean, Google "Linux file permissions".
You may (out of habit) insert a space after the comma that separates the mount_options
array. Don't. It won't work with a comma.
The id
can be anything you want.
Best Answer
The format for shared folders changes across different versions of Vagrant. See Fabio's answer https://serverfault.com/questions/398414/vagrant-set-default-share-permissions
Vagrant version 1.3.1 and earlier
config.vm.share_folder "v-data", "/export", "/export", :owner => 'vagrant', :group => 'httpd', :extra => 'dmode=775,fmode=775'
Vagrant version 1.3.1, 1.3.2
In Vagrant 1.3.1 and later, the
extra
option has been replaced withmount_options
that expects an array.config.vm.share_folder "v-data", "/export", "/export", :owner => 'vagrant', :group => 'httpd', :mount_options => ['dmode=775', 'fmode=775']
Vagrant version >=1.3.3
In vagrant 1.3.3 it appears
config.vm.share_folder
has been replaced withconfig.vm.synced_folder
.config.vm.synced_folder "v-data", "/export", "/export", :owner => 'vagrant', :group => 'httpd', :mount_options => ['dmode=775', 'fmode=775']