skip to Main Content

How to set the right folders / files permissions for a website on a Linux server ?

What Permissions Should My Website Files Folders Have On A Linux Webserver

When you decide what permissions to use on your web server, you need to know exactly who your users are and what they need. A web server serve for two types of user.

  1. Authenticated users have a user account on the server and can be provided with specific privileges. This usually includes system administrators, developers, and service accounts. They usually make changes to the system using SSH or SFTP.
  2. Anonymous users are the visitors to your website. Although they don’t have permissions to access files directly, they can request a web page and the web server acts on their behalf. You can limit the access of anonymous users by being careful about what permissions the web server process has. On many Linux distributions, Apache runs as the www-data user but it can be different. Use ps aux | grep httpd or ps aux | grep apache to see what user Apache is using on your system.

Suppose that Apache is using on your system. Please follow the step below:

Step 1

This command below sets apaches as the owner of every file and folder inside the directory html. And then change permission of html directory to 0770

sudo chown apache:apache /var/www/html
sudo chmod 0770 html

Step 2

First command below sets ftp_user as the owner of folders and files that are sub of html directory (-R stands for recursive). Second command changes permission of sub folder of html directory to 0770. And the last one command changes permission of all files to 0644.

sudo chown ftp_user:apache -R /var/www/html/*
sudo find /var/www/html/* -type d -exec chmod 0770 {} \;
sudo find /var/www/html/* -type f -exec chmod 0644 {} \;

Source

https://serverfault.com/questions/357108/what-permissions-should-my-website-files-folders-have-on-a-linux-webserver

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top
Search