Linux directory permission inheritance for new files created

-1

ive following folder

 drwxr-xr-x   7 root root 45056 Nov 25 12:39 data

which include sub dirs and files its all 755 ,

but when i create new file inside these dir its get permission

-rw-r--r-- 1 root root    0 Nov 28  2013 new

how to make new files create in these dir take 755 without doing it manually i tried chmod g+s and nothing happen ,

anytips

Marco DonJuan

Posted 2013-11-28T10:37:29.230

Reputation: 133

Answers

0

The only way to set the bit permissions is via your umask. When a file is created, say with permissions 666 (this is in octal), your umask decides which bits are flipped to 0.

To explain further: rwx rwx rwx is for User Group World respectively. If each bit was set to 1 (111 111 111) this would be 0777 (in octal). 0666 is 110:110:110 or rw_rw_rw. Hope that makes sense.

Your umask will, by default, be 022 - (octal 022). This says which bits are to be kept (0) and which are not (1). (It's slightly non-intuitive that way).

Take a 666 created file: 6 & ~0 = 6 6 & ~2 = 4 6 & ~2 = 4

Thus the created file will have permissions of 644 (rw-r--r--).

Note that the effect of umask is to mask off the bits that are given to the file create call. If the call takes 666, there is no way to make it 755 without doing a "chmod a+x file" manually.

Also, the effect of g+s, setting group suid, is to set the owning group, not the bit permissions. Windows is far more fine grained in this respect (ACLs) but there are file system extensions to add ACL permissions to Linux file systems.

carveone

Posted 2013-11-28T10:37:29.230

Reputation: 318