Set ownership on uploaded files
I have set up Apache and vsftpd on Ubuntu. I'm pretty new to Linux, but I'm trying to figure how to set ownership automatically.
When I upload files through FTP, I can't access them until I set ownership to www-data.
I need to do this each time I upload something:
sudo chown -R www-data:www-data /folder/
How to make this happen automatically?
Solution 1:
-
Change group of all files/directories recursively to www-data group
chgrp -R www-data /folder/
-
Give write permissions to the group recursively
chmod -R g+w /folder/
-
Add the desired ftp users to the www-data group
usermod -a -G www-data ftp_user
Now ftp_user should have read/write access to /folder/ and subfolders. That means that he/she can upload files but those files will have ftp_user as owner and group. In other words the web server user (www-data) will not have write access to the files. To ovecome this discrepancy you can set the SGID on the parent directory.
chmod g+s /folder/
From now on each file / directory created by ftp_user will have as owner the ftp_user but the group will be automatically changed to www-data.