Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 4 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
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

Your Answer


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.