Linux: Setting Default Owner and Permissions in a Folder (when uploading with SFTP)
Sometimes it is necessary to have all files in a folder to be created with the same group and permissions. This is most useful where multiple users have access to a shared folder, and all those users need to be able to access any files created there.
Firstly all the users should be members of the same group.
Create the group if necessary:
sudo groupadd my_group
Then add the users to the group:
sudo usermod -a -G my_group user1 sudo usermod -a -G my_group user2
Now set the default group permissions on any files folders created within:
setfacl -m "default:group::rwx" my_folder
If you are using SFTP to upload files to the folder, you also need to set the umask for files uploaded by FTP to allow the group write bit to be set. For Openssh, edit /etc/ssh/sshd_config and adjust the Subsystem line from:
Subsystem sftp internal-sftp
Subsystem sftp internal-sftp -u 0002
When using SFTP, it will take the permissions of the file being uploaded, so you also need to ensure that the uploaded file has group write set, or adjust it once uploaded.
Date: June 26, 2017
Category: Linux Admin Tips
Author: John Taylor