I would use 664 (rw-rw-r--) instead of 770 (rwxrwx---) for files (default is (rw-r--r--), so files can be read by everyone
and execution bit is not set.
For directories (where default is rwxr-xr-x) you need the execution bit to enter the directory and access files.
With setgid
newly created files automatically belong to the group of the directory (and not to the default group of the user who created the file),
so other users of the same group can modify them.
If your directory is /var/www/html
and your group with write permission is www-data
, this is all you need:
Change directories to 2775 (rwxrwsr-x) with setgid
set.
find /var/www/html -type d -exec chmod 2775 {} +
Only set setgid
on directories (if the other permissions are already correct)
find /var/www/html -type d -exec chmod g+s {} +
Change files to 664 (rw-rw-r--)
find /var/www/html -type f -exec chmod -v 664 {} +
Change group recursively to www-data
chgrp -R www-data /var/www/html
Or change user and group recursively to www-data
chown -R www-data:www-data /var/www/html
You can add the verbose -v
option to the above commands to see what was changed.