Answer the question
In order to leave comments, you need to log in
Linux and Permissions
how to make files automatically assigned the owner/group of the folder in which they are created?
Answer the question
In order to leave comments, you need to log in
Use sgid:
chmod g+s /dir
For example:
mkdir Test
ls -l | grep Test
drwxrwxr-x 2 zombic zombic 4096 2011-10-12 13:36 Test
cd Test/
touch file.txt
ls -l
итого 0
-rw-rw-r-- 1 zombic zombic 0 2011-10-12 13:37 file.txt
sudo touch file2.txt
ls -l
итого 0
-rw-r--r-- 1 root root 0 2011-10-12 13:37 file2.txt
chmod g+s ../Test/
sudo touch file3.txt
ls -l
итого 0
-rw-r--r-- 1 root root 0 2011-10-12 13:37 file2.txt
-rw-r--r-- 1 root zombic 0 2011-10-12 13:38 file3.txt
-rw-rw-r-- 1 zombic zombic 0 2011-10-12 13:37 file.txt
This can be done with the setfacl command set, for example:
Let's say we have a sales group.
Let's create a Sales directory for read and write access to users in the sales group.
mkdir -m 700 Sales
setfacl -md:g:sales:rwx,g:sales:rwx Sales
The first command creates a directory with root-only permissions, the second will set the same permissions for the sales group.
everything that will be created by the users of the group and even the root will inherit the access attributes.
There is a lot of information on this material on the Internet.
The file's owner and group are set according to who created the file.
Alternatively, you can solve the issue by creating a script that, when creating an object, would calculate the attributes of the parent and set the rights.
If I correctly understood everything, then it is the best of all for you to use ACL.
setfacl -m default:user:iivanov:rw managerdata
For files and directories created in the managerdata directory, add read/write permission for user iivanov.
Thanks everyone for the replies, as I thought there are several ways
Just keep in mind that sgid or ACL based solutions only work for new files. If you use mv it won't work.
A reliable solution is bindfs.
I've tried all of these ways, but none of them really worked. Bindfs came up - with it I managed to set everything up exactly the way I needed it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question