LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Setting Sticky Bit recursively ONLY on directories (https://www.linuxquestions.org/questions/linux-newbie-8/setting-sticky-bit-recursively-only-on-directories-816005/)

CNBarnes 06-23-2010 05:07 PM

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?

rweaver 06-23-2010 05:37 PM

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)

crts 06-23-2010 05:59 PM

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.

CNBarnes 06-24-2010 08:20 AM

Quote:

Originally Posted by crts (Post 4013164)
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.

anomie 06-24-2010 02:45 PM

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 {} \;

rweaver 06-25-2010 01:33 PM

Quote:

Originally Posted by anomie (Post 4013932)
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.


All times are GMT -5. The time now is 11:22 AM.