Webserver permissions once and for all

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:

  • Of course my web-server needs to execute/read/write to files
  • My nginx is run by www-data and /var/ww/html/ folder is owned by www-data user & group
  • I need my deployment service to write/delete in /var/www/html. It has it’s own user and is a part of www-data group.
  • I need my own user to be able to write/delete (when configuring, testing, changing, etc), without using sudo. I am also a part of www-data

Currently 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

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hey, @mattiasf


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.