• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

Default Directory Permissions

How do I change the default permissions for a new file created in a directory?

I have a directory used for a group project. When a member of that group creates a file, I want the file to be changed to group read and write, as though they had done a chmod 660 <file> and a chgrp <group> <file>.
0
bergsy
Asked:
bergsy
  • 2
1 Solution
 
gruseCommented:
Do a

chmod g+s /your/project/dir

This way, every new created file in this directory will belong to the project group (same group as your project dir). Then check your umask by typing

umask

It's probably 027 or 077. Newly created files typically get 666 (777) permission, but the umask value gets subtracted (well, actually the file's permissions get NOT-ANDed against the umask value). Set the umask value to 007 as in

umask 007

(or 002, if others are allowed to peek), and any file you create now in that dir will have the correct set of permissions. It is easiest to add that command to your shells global profile file (/etc/profile or /etc/bashrc, differs with your login shell), so that every user gets that umask value set at login.

Hope that helped!
0
 
jlevieCommented:
If you mean how can I have this automatically happen, the only way would be to change the user's umask to 002.
0
 
jlevieCommented:
Going off gruse's post...

Setting group id on execution (chmod g+s) just means that files created in that dir take on the group ID of the dir. It does not affect the group r/w modes.
0
 
bergsyAuthor Commented:
I never knew about the +s attribute on chmod, that helps a lot!
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now