I have (I guess basic) problems with Linux permissions/ownership.

I have FTP user "ftp". Then I have all files on my server under different user "nginx".

To make the websites work I need to have all files set to user nginx otherwise they return various errors.

To change files on the server on FTP I need to have permissions set to user "ftp" otherwise I get permissions denied when I try to edit the files.

How to solve this with?

Right now I have to always do chown -R ftp:ftp when I want to edit some files through FTP.

  • some related questions – cascer1 Nov 9 '16 at 11:09
  • 2
    Figure out who should be the actual owner and who should have access rights. Set the owner/group accordingly by e.g. using sticky bits and fixing either of those parameters. Don't forget about other/world though you probably don't want to give those access it's still an option. – Seth Nov 9 '16 at 11:33

It sounds like you need a common group for both ftp and nginx. In your case you can probably use the ftp group for this. I don't know if your web server needs write access to the files, but if not, cd into your content directory and run these commands:

chown -Rh ftp:ftp .
find . -type d -exec chmod g+rxs {} \;
find . -type f -exec chmod g+r {} \;

If you do need write access from web server, do this instead:

chown -Rh ftp:ftp .
find . -type d -exec chmod g+rwxs {} \;
find . -type f -exec chmod g+rw {} \;

These commands will make everything owned by ftp:ftp and make these files readable and (in the second case) writable by anyone in the ftp group. It also sets the setgid bit on all the directories which will make all new files owned by the ftp group. Once this is done, add the nginx user to the ftp group:

usermod -a -G ftp nginx

and restart your web server so it will take effect.

You may also need to force all files written to these directories to be writable by the group. You can do this by setting the umask for your ftp and web servers to 002, or with an acl:

setfacl -Rdm g::rwx .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.