Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want all files in directory /home/alex/foo to be owned by alex, no matter who creates them. I'm trying this technique, but it doesn't work (on CentOS 5, under root):

$ cd /home/alex
$ mkdir foo
$ chmod u+s foo
$ chown alex foo
$ ls -al . | grep "foo"
drwsr-xr-x  2 alex root      4096 Nov 14 14:18 foo
$ echo "test" > foo/test.txt
$ ls -al foo
total 12
drwsr-xr-x  2 alex root   4096 Nov 14 14:19 .
drwxr-x--- 13 alex root   4096 Nov 14 14:18 ..
-rw-r--r--  1 root root      6 Nov 14 14:19 test.txt

As you see, the file is owned by root, but should be owned by alex. What am I doing wrong?

share|improve this question
    
You know you can do ls -ld foo instead of using grep? –  Dennis Williamson Nov 14 '10 at 15:52
    
@Dennis Now I know, thanks :) –  yegor256 Nov 14 '10 at 16:05
add comment

1 Answer

up vote 3 down vote accepted

setuid on directories does not work like setgid on directories in *nix.

share|improve this answer
    
to expound, an average user (not root) doesn't have the permission to set a file as another's userid. Technically this is CAP_FOWNER (and maybe CAP_FCHOWN) and as far as I'm aware, root is the only user with a CAP_FOWNER capability in Linux. –  troyengel Nov 14 '10 at 14:43
1  
You mean that my use case is not going to work, by design? –  yegor256 Nov 14 '10 at 15:14
    
That is correct. –  Ignacio Vazquez-Abrams Nov 14 '10 at 15:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.