Reputation: 4191
In order to create a shared folder for a given group of users, I need restricted directory rights with inheritance. The goal is that only root and users members to the specified group can read & wright inside, by inheritating these rights for future content in my directory. Something like:
drwxrws--- 2 root terminator 6 28 mai 11:15 test
I am able to obtain this with 2 calls of chmod:
chgrp terminator test
chmod 770 test
chmod g+s
It would be nice to do this in one command using a numeric mask. I need to use a mask, because it is a python script who is supposed to do the job using os.chmod(). Thanks!
Upvotes: 3
Views: 4288
Reputation: 24
You can set the sticky bit from the command line with one call of the chmod command like so:
chmod 2770 test
The preceding '2' sets the sticky bit for the group.
os.chmod() appears to need a preceeding zero so that it knows the digits are octal. I've tested the following successfully:
import os
os.chmod('test', 02770)
Upvotes: 0
Reputation: 69082
os.chmod
does exactly the same as the chmod
utility, but you need to remember that the argument to chmod
is a string representing a bitmap in octal notation, not decimal. That means the equivalent to
chmod 2770 test
is
os.chmod('test', 0o2770)
You probably used os.chmod('test', 2770)
, which would be 5322
in octal, which is consistent whit the bitmask you seem to get.
Upvotes: 3
Reputation: 123608
chmod u+rwx,g+rws,o-rwx test
should do what you want.
Alternatively, the following should do it from within a script:
import os
import stat
os.chmod('test', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_ISGID)
Upvotes: 2