window window window window - 2 months ago 13
Linux Question

File permission in ubuntu

I have a VPS and use it for hosting my sites. The server is nginx with php-fdm.
my site is in the

/var/www/sitename/html/
and all the files and folders under the html directory owned by
www-data www-data
. All files permision is
664
and directories (html folder and sub-directories) has
775
permission. And also my user is member of the
www-data
group.

I can change every files in this folder, but I can't make new file or new folder here. This need
sudo
privileges. I can create new file in the sub-directories like
/var/www/sitename/html/uploads
but not in the
/var/www/sitename/html/
while they have the same owner and permission.

Answer

The user you are logging in as is not the www-data user or a member of the www-data group.

I set things up on my servers so that the user I log in as owns the files/directories, and a webuser group is the owning group, perms are set to 750/640. You can automagically keep the owning group the same across all files/directories uploaded to/created on the server by making the top level web directory setgid.

drwxr-s---  4 debbie www-data  4096 Oct  6  2015 /var/www-debbie.example.com

If the webserver needs to write files, create the directory and change the permissions on it

sudo mkdir /var/www-debbie.example.com/writeable
sudo chmod 770 /var/www-debbie.example.com/writeable

If you haven't done the setgid thing, then fix the ownership

sudo chown debbie.www-data /var/www-debbie.example.com/writeable

And there ya go, the web server user can write to it.

drwxrws---  4 debbie www-data  4096 Oct  6  2015 /var/www-debbie.example.com/writeable