Automatically change permissions/ownership of files in a directory
Hi, my friend and I created an FTP server to drop files into so we can share them anytime. His user is 'david' and mine, 'shimdidly'. We are using vsftpd. We created a special folder called 'share' where we put all of our files. When one of us uploads a file through FTP, the file is placed in the folder with the user and group set to whoever uploaded it. If 'david' uploaded the file, it would read
Code:
-rwxrwx--- 1 david david So I want to set it up so that any files/folders within the share folder automatically fall under the group 'share'. Sure I can SSH into the server run 'sudo chgrp -R share share' after every file upload. But that is cumbersome. |
You want to enable the setgid bit on the directory containing the files.
See: Wikipedia: Filesystem Permissions In practice: 1. Navigate to the parent of the directory containing the files (e.g. if /var/ftp/userfiles contains the files, navigate to /var/ftp) 2. Change the ownership of the directory containing the files to group 'share.' Code:
root@localhost# chown :share userfiles Code:
root@localhost# chmod g+s userfiles Note: you will need to manually correct any pre-existing files or directories at the time you set the setgid bit. Note2: you will also, of course, need to make sure that you and your friend belong to the share group. |
Thanks very much!
|
Glad I could help.
One other thing I wanted to mention: The setgid bit on the directory takes care of the initial group assignment. It does not enforce group ownership after that point. In other words, the setgid bit will not prevent a user with appropriate permissions from manually changing the group ownership at a later date. |
All times are GMT -5. The time now is 03:35 PM. |