How can I set permissions for www-data on NEW folders and files PERMANENTLY?

Ubuntu 20.04 VPS

I've read multiple threads on this and still don't get it. I have an FTP user deanhh for ONE of multiple virtual hosts in apache2. There are other FTP users also, for other domains. Deanhh is the owner of his domain's folder. When he creates a folder or creates and uploads a file via FTP he is the owner of the folder/file. That's what I want.

BUT the file has no permissions on it for other. I set umask 0000 on the telnet command line yesterday. Everything worked fine. When deanhh uploaded a file via FTP it inherited the permissions of the folder. Now umask is back to 0022 so when he uploads a new file or creates a folder there are no permissions on it for other.

How do I set it so that when an FTP user creates a folder or uploads a NEW file, they retain ownership AND 'other' has the permissions that were set for 'other' on the folder the file was uploaded to - PERMANENTLY?


Solution 1:

The simplest way would be to edit the /etc/login.defs file. Here's how:

  1. SSH into the server
  2. Open the /etc/login.defs file with sudo:
    sudo {your editor of choice} /etc/login.defs
    
  3. Find the row that starts UMASK. It may be around line 155 and look like this:
    UMASK           022
    
  4. Change 022 to whatever value you prefer
  5. Save the file and exit

The next time a person connects to their account, be it SSH or FTP, the appropriate umask will be applied.