Linux – Set Default User / Group (Sticky Bit) in Ubuntu

chmodlinuxpermissionsSecurityUbuntu

To enforce the following permissions on files in /var/www, can I use the commands chmod u+s and chmod g+s?

Permissions:

chown -R root:web /var/www
chmod -R g+rw /var/www

Best Answer

Setting the setgid bit on a directory will cause files and directories to inherit the group ownership of that directory. It will not have any impact on file or directory permissions.

File and directory permissions are controlled primarily by the process umask, which you can set for example in the Apache startup script.

To do what you want, you would first need to recursively set the setgid bit on all the directories in /var/www, and would would need to fix the permissions on existing files, and you would need to make sure all the existing files/directories have appropriate user and group ownership, and you would need to arrange for Apache to use the appropriate umask.