System Administration
Showing results for 
Search instead for 
Did you mean: 

default create perms on files for everyone

Go to solution
Jason Moorhead_2
Frequent Advisor

default create perms on files for everyone

Hi All,

What I'm trying to do is set my Red Hat 5.5 server so that any file created in a certain directory (by any user) is readable and writable by any other user.

This directory is a temp directory that is used very often to move files between users and our ERP system, and needs to be as wide open as possible. I realize a chmod command can do this, but there are thousands of files in here throughout the day, so that's not really a feasible solution.

Is this something that an ACL could be used for? Basically, anything created in /usr/tmp needs to be readable and writable by everyone at all times.

Hopefully that is enough info! Seems like it should be easy enough to do, but after days of googling and testing, I haven't figured it out. :)

Honored Contributor

Re: default create perms on files for everyone

> any file created in a certain directory (by any user) is readable and writable by any other user.

I see why you're thinking "world writable" as a possible solution, but I'd recommend you to approach this problem in a different way.

Your ERP system is probably running on some particular user account.

1.) Create a group using any name you want. For example, "tempdir":

groupadd -g 999 tempdir

(Choose the group ID so that it won't interfere with any normal user accounts.)

2.) Then add the ERP system account and all the human users on the system to that group. Since users can belong to multiple groups simultaneously, this should not be a problem.
(You don't need to change the users' _primary_ group: this can and probably should be a secondary group.)

gpasswd -a erpuser tempdir
gpasswd -a user1 tempdir
gpasswd -a user2 tempdir

Note: while "usermod -G tempdir " would achieve much the same thing, the "gpasswd" command will automatically _add_ the new group to the user's current group memberships. With "usermod -G", you would have to check the user's current group memberships and explicitly list all the secondary groups you would want for the user.

3.) Restart the ERP system, so that all its processes will be aware of the new group membership.

4.) Set the group of the temporary directory to "tempdir", and permissions to 2775 (drwxrwsr-x):

chgrp tempdir /usr/tmp
chmod 2775 /usr/tmp

This enables the "setgid" feature on the temporary directory (unless it's prevented by filesystem mount options). Now all the files created to this directory will get "tempdir" as the group owner automatically. All sub-directories created will automatically inherit both the group owner and the setgid feature.

Since now both the ERP system and the users will belong to the "tempdir" group, having the directory and the files group writable will be sufficient: no world-writability is required.

System daemons that are unrelated to the ERP system and are running on a specific account of their own will still be prevented from writing to the directory (or from accessing it at all if you want), which is good security.

5.) Make sure the users' umask allows group write permissions (this might be correct by default?)

If you want users' files to be world-readable by default, add "umask 002" to the end of users' login scripts. If that's too much, you might use "umask 007" instead.

(This might even be unnecessary, if the ERP system only needs to read & delete user-created files, and write its own files: remember that file deletion is not controlled by the write permission on the file itself, but by the write permission on the _directory the file's in_.)


Now, if user1 creates a non-executable file in anywhere other than the special directory, the file permissions & ownerships will be:

-rw-rw-r-- user1 user1 ...

Since the default group "user1" contains only user "user1", the group-writeability won't cause any harm.

In the special directory, the permissions & ownerships will be:

-rw-rw-r-- user1 tempdir ...

Since the ERP system will be a member of the tempdir group, it can write to the file. Because the directory is also writable by the tempdir group, the ERP system can delete any file in the directory.

Jason Moorhead_2
Frequent Advisor

Re: default create perms on files for everyone

Thanks Matti,

I hadn't actually thought about using groups and setting the guid bit on the directory.

For some reason, I was hoping that there would be a way to set the ACL on the directory to give worldwide read/write perms to every file in it, regardless of how it was created (ftp, samba, shell, etc).

Unless I hear something else in the meantime, I will give your idea a try when I get a chance for a bounce of the ERP.

Thanks again for all the info!