Linux – How to give write permissions to multiple users

best practiceslinuxpermissions

I have a web server and I'm uploading files using an FTP client. Because of that the owner and the group of the file are taken from the user used during the upload.

Now I have to make this file writable by the web server (apache/apache).

One way would be to just change the owner and the group of the uploaded file to apache/apache, but that way I cannot modify the file using the FTP account. Another way would be to give the file 777 permissions.

Both approaches seem not very professional and a little bit risky. Are there any other options? In Windows I can just add another user to the file. Can something similar done with Linux?

Best Answer

You can change the group of the files:

groupadd webusers
usermod -aG webusers the_user_name
chgrp -R webusers the_directory
chmod g+s the_directory

If this is a RedHat based distribution you can use setfacl to do this without a group and set it to happen by default:

setfacl -R -m user:the_username:rwx directory_name
setfacl -d -R -m user:the_username:rwx directory_name
Related Topic