Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-08-2012, 03:07 PM   #1
LQ Newbie
Registered: Mar 2012
Posts: 21

Rep: Reputation: Disabled
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
-rwxrwx--- 1 david     david
I don't want 'everyone' to have any permissions. I only want users part of the group 'share' to be able to r/w/x any of the files in the share folder.
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.
Old 04-08-2012, 03:16 PM   #2
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
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.'
root@localhost# chown :share userfiles
3. Apply the setgid bit:
root@localhost# chmod g+s userfiles
From that point on, any files created in userfiles will automatically belong to the share group. Further, any subdirectories created will also belong to group share and will also inherit the setgid bit.

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.

Last edited by Dark_Helmet; 04-08-2012 at 03:17 PM.
1 members found this post helpful.
Old 04-08-2012, 08:17 PM   #3
LQ Newbie
Registered: Mar 2012
Posts: 21

Original Poster
Rep: Reputation: Disabled
Thanks very much!
Old 04-08-2012, 08:22 PM   #4
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change ownership of an entire directory. Shay Linux - Newbie 3 07-02-2010 09:03 PM
Change ownership of all games at once? Or remove permissions? okos Slackware 7 01-16-2010 01:19 PM
effect of attempting change of /FS ownership or rwx permissions ruchinder Linux - Newbie 2 08-09-2009 07:06 PM
Compiling: permissions, ownership of files ... JosephS Slackware 1 12-22-2007 01:04 PM
recursive file permissions does not change new files in same directory PAB Linux - Newbie 2 03-08-2004 12:27 PM

All times are GMT -5. The time now is 02:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration