By mattiasf
So after hours and hours of looking around tons of links and websites, all pointing people in different directions in terms of “the correct” or “best practice” for file-permissions on a webserver, I still haven’t found a solid answer.
What also surprises me is that I have seen no real information in official documentations regarding such a vital aspect of configuring a webserver on nginx (or apache for that matter).
I have the following scenarios that will need to be taken care of:
www-data and /var/ww/html/ folder is owned by www-data user & group/var/www/html. It has it’s own user and is a part of www-data group.www-dataCurrently I’m inclined to use 775 on everything, but I know and feel this is wrong.
After running chmod 775 -R /var/www/html the permission syms looks weird: drwxrwsr-x (it seems to be an invalid one, and no online chmod calculator I have found can translate it to anything - they all say it’s invalid). The ls -la command in /var/www returns this:
mattias@jwlry:/var/www$ ls -la
total 12
drwxrwsr-x 3 www-data www-data 4096 Sep 24 17:05 .
drwxr-xr-x 14 root root 4096 Sep 24 17:05 ..
drwxrwsr-x 4 www-data www-data 4096 Sep 25 09:45 html
Please enlighten me
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey, @mattiasf
3
The s in rws stands for setuid meaning set user ID. This is a special permission bit that allows the program, when run by any user, to be run with the effective UID of the owner, in this case, www-data. So when you as a normal user run the sudo executable, you effectively do so as www-data. This permission bit is a security risk, and should only be applied where absolutely necessary.
Explanation of the setuid bit:
When applied to an executable file, it sets the effective user ID from that of the real user (the user actually running the program) to that of the program’s owner. Most often this is given to a few programs owned by the superuser. When an ordinary user runs a program that is “setuid root” , the program runs with the effective privileges of the superuser. This allows the program to access files and directories that an ordinary user would normally be prohibited from accessing. Clearly, because this raises security concerns, the number of setuid programs must be held to an absolute minimum.
To remove the setuid bit use the -s argument with the chmod command:
chmod u-s /path/to/file
Let me know if you have any questions.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.