LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices



Reply
 
Search this Thread
Old 04-08-2012, 04:07 PM   #1
Shimdidly
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
Code:
-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, 04:16 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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
3. Apply the setgid bit:
Code:
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 04:17 PM.
 
1 members found this post helpful.
Old 04-08-2012, 09:17 PM   #3
Shimdidly
LQ Newbie
 
Registered: Mar 2012
Posts: 21

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

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


Reply


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 10:03 PM
Change ownership of all games at once? Or remove permissions? okos Slackware 7 01-16-2010 02:19 PM
effect of attempting change of /FS ownership or rwx permissions ruchinder Linux - Newbie 2 08-09-2009 08:06 PM
Compiling: permissions, ownership of files ... JosephS Slackware 1 12-22-2007 02:04 PM
recursive file permissions does not change new files in same directory PAB Linux - Newbie 2 03-08-2004 01:27 PM


All times are GMT -5. The time now is 12:25 AM.

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