Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 to create a directory where any user can create a file, but after creating the file the user and group ownership for that file are set to predefined values. I know there is a way to do this with GUID, UID but I'm always forgetting the chmod combo.

share|improve this question
up vote 6 down vote accepted

You can do this for GID:

chgrp users /path/to/directory
chmod g+s /path/to/directory

You cannot do this for UID. Directly.

You could write a cron entry that every so often runs the commands:

chown -R user:group /path/to/directory
chmod -R 644 /path/to/directory

(make sure you mount the filesystem that /path/to/directory is on nosuid to avoid a race condition where someone drops a setuid shell into the directory)

share|improve this answer
chgrp users /path/to/directory chmod g+s /path/to/directory That's all that I was looking for, this biscuits for you – Jake McGraw Jul 9 '09 at 22:01
Another thing that helps is you set the umask properly for the users – Zoredache Jul 9 '09 at 22:03

chown user:group file ?

share|improve this answer

I'm sorry to say that, but RTFM please. From chmod(1):

       Modes may be absolute or symbolic.  An absolute mode is an octal number
       constructed from the sum of one or more of the following values:

       4000    (the setuid bit).  Executable files with this bit set will
               run with effective uid set to the uid of the file owner.
               Directories with this bit set will force all files and sub-
               directories created in them to be owned by the directory
               owner and not by the uid of the creating process, if the
               underlying file system supports this feature: see chmod(2)
               and the suiddir option to mount(8).
       2000    (the setgid bit).  Executable files with this bit set will
               run with effective gid set to the gid of the file owner.
       1000    (the sticky bit).  See chmod(2) and sticky(8).
       0400    Allow read by owner.
       0200    Allow write by owner.
       0100    For files, allow execution by owner.  For directories,
               allow the owner to search in the directory.
       0040    Allow read by group members.
       0020    Allow write by group members.
       0010    For files, allow execution by group members.  For directo-
               ries, allow group members to search in the directory.
       0004    Allow read by others.
       0002    Allow write by others.
       0001    For files, allow execution by others.  For directories
               allow others to search in the directory.
share|improve this answer

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.