LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-23-2010, 06:07 PM   #1
CNBarnes
Member
 
Registered: Apr 2004
Location: Texas
Distribution: Debian
Posts: 41

Rep: Reputation: 15
Setting Sticky Bit recursively ONLY on directories


I have a folder that contains my group's website. The ownership of the entire directory is set to "www-data.website" (website being a group). I want to set the sticky bit on this directory such that if anyone creates a new file, either in the main directory or subdirectories, the ownership remains like above.


Q1: I have the sticky bit set on the main directory (drwxrwsr-x). But for some reason, some of the subdirectories don't have the sticky bit set. Is there a command I can use to change the sticky bit on DIRECTORIES ONLY (ie. not on the fiiles)?

Q2: is there a sticky bit that I can set for the ownership (not group) so that it is always set to www-data?
 
Old 06-23-2010, 06:37 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
You could use find...

Code:
find /var/www/dir -type d -exec echo chmod 2755 {} \;
If that shows what you want to change... remove the echo (nee: sub whatever chmod command you like)

Last edited by rweaver; 06-23-2010 at 06:39 PM.
 
1 members found this post helpful.
Old 06-23-2010, 06:59 PM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,608

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi,

you are setting the sgid bit on the directory, not the sticky bit.

As for your second question: The suid bit on a directory is ignored in Linux. But you can change ownership after the file has been created.
I once did that using incron. You can monitor the directory with this daemon and take appropriate actions when the CREATE event is being triggered. In your case this would be a chown on the newly created file.
 
1 members found this post helpful.
Old 06-24-2010, 09:20 AM   #4
CNBarnes
Member
 
Registered: Apr 2004
Location: Texas
Distribution: Debian
Posts: 41

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by crts View Post
As for your second question: The suid bit on a directory is ignored in Linux. But you can change ownership after the file has been created.
I once did that using incron. You can monitor the directory with this daemon and take appropriate actions when the CREATE event is being triggered. In your case this would be a chown on the newly created file.
You know, I have noticed that in the past, but never really had enough time (or curiosity) to look it up to try to figure out why.

Thanks for the suggestion on incron.
 
Old 06-24-2010, 03:45 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by rweaver
You could use find...

Code:
find /var/www/dir -type d -exec echo chmod 2755 {} \;
For an ad-hoc change, I second this approach, but I'd recommend just adding the sgid bit (rather than re-defining all permissions for the directory). A la,
Code:
# find /foo -type d -exec chmod g+s {} \;

Last edited by anomie; 06-24-2010 at 05:10 PM. Reason: sticky != sgid
 
Old 06-25-2010, 02:33 PM   #6
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by anomie View Post
For an ad-hoc change, I second this approach, but I'd recommend just adding the sgid bit (rather than re-defining all permissions for the directory). A la,
Code:
# find /foo -type d -exec chmod g+s {} \;
Generally good advice, the only reason i typically set it otherwise for webserver directories is because of how particular they are on permissions compared to most applications. Although a great deal depends on how well you know what data and services/applications you're dealing with specifically.
 
  


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
copy recursively across directories stefaandk *BSD 1 11-09-2008 11:01 PM
sticky bit: how to protect directories but not files inside alexandrusa Linux - Server 8 03-27-2008 11:35 AM
Sticky bit on / and /home directories? keysorsoze Linux - Newbie 6 01-21-2007 06:56 PM
ProFTPD: Set umask so that directories are created with 'sticky bit' on. dutch2005 Linux - Software 1 09-06-2005 06:06 AM
Can ls recursively list only directories? Vosper Linux - General 3 07-16-2005 04:57 AM


All times are GMT -5. The time now is 12:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration