# Changing default permissions for a directory

## tyreth

How do I change the default permissions for a directory?  I have a directory that I want multiple users of a specific group to be able to access, and be able to modify any file that is created in it.  It is too much of a hastle to change the perms every time the file is written.  How do I tell linux, that for every file or directory created under this particular directory, should belong to <this> group with <these> permissions?

Any help appreciated.  Thanks.

----------

## klieber

 *tyreth wrote:*   

> How do I tell linux, that for every file or directory created under this particular directory, should belong to <this> group with <these> permissions?

 

Set the group ID on the parent directory.  Then, make sure that parent directory is group-owned by <this> group.

So, if you have a directory, foo and a group named, bar, you would do something like the following:

```
# chown root.bar foo

# chmod -R 2770 foo

```

The "2" in the above command tells linux to use the group ID of the parent directory, rather than the group ID of the process writing the file. Obviously, change the "root" and "770" parts to suit your particular permissioning requirements.

Setting UID and GID on files and programs can expose your system to large security holes (such as normal users running programs as root) so use this feature with caution.  

--kurt

----------

## tyreth

Thanks, it's keeping the group I set, but permissions still change by default to 554 for files that are newly created.

Any way I can tell it to keep 770 for newly created files?

----------

## klieber

 *tyreth wrote:*   

> Any way I can tell it to keep 770 for newly created files?

 

Yep -- set the umask correctly.  man umask or do a google search.

--kurt

----------

## tyreth

As far as I can tell umask does not do what I want.

It changes the permissions I use, but I want to change the default permissions of any user creating files in that directory.

I have a project that has it's own directory, with 2 people working on it.  Every time either of us create a file it defaults to 744, I want it to go to 774 or 770 for every user that creates a file in that directory, not just me.

----------

## klieber

 *tyreth wrote:*   

> I want it to go to 774 or 770 for every user that creates a file in that directory, not just me.

 

In the user's .profile (or .bash_profile or whatever) put:

```
#sets the umask for default permissions

umask 007
```

Change that to 'umask 003' if you want 774 default permissions.

AFAIK, you cannot limit default permissions to one directory -- it's defined on a per-user basis, through the use of umask in the users' profile

--kurt

----------

