Are these webroot permissions correct ?

I’m relatively new to permissions, so I might be doing this wrong, which is why I am checking with you (the reader). I have been wondering how I would have to set my webroot permissions for ‘regular website hosting’ on my VPS. I understand there are tens of ways of doing it, depending on the security one needs, but after reading some tutorials I came to the following situation :

1.) sudo chown -R <myself>:www-data /var/www 2.) sudo chmod -R 755 /var/www 3.) sudo chmod g+s /var/www

1.) I’m setting <myself> and the www-data group as owners of the webroot. 2.) I’m changing the permissions recursively on the webroot so that <myself> has all permissions, NGINX has read & execute and the world also has read & execute. 3.) New files that are added (through SFTP or the shell) will inherit the same configuration of permissions / ownership.

In case of dynamic pages generated by wordpress I will leave it this way but set different permissions for folder where NGINX needs to write, such as ‘upload’ folders, and / or ‘plugin’ folders. etc.

1.) sudo chmod 775 /var/www/… <upload> 2.) sudo chmod 775 /var/www/… <plugin folder>

The question however is : I am doing all this in the right way ? Or am I going about it all wrong ?

Thanks in advance

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.

This comment has been deleted

I will recommend changing user for /var/www directory to www-data (or the user you are using for nginix). This way nginx has full permissions to files in /var/www.

You can add yourself to the www-data group. And set /var/www permission to 775 or 765. By doing this users in the www-data group will be able to execute (if you use 775) or read/write (if you use 765).