简体   繁体   中英

Creates folder/file with second user permission on linux Centos

Linux permission question:
I have one folder "test" with a permission group "test", the primary group for "test" user is "users" and the second group is "test" How to make the second group "test" to receive permission when a user "test" is create a folder or file in the /test directory?

The group "users" don't need to have access to the "test" user folder.

After the user "test" creates a new folder/file inside the "test" directory it need to be will show as following:

$ll /test drwxr-xr-x 2 test test qa/

not: $ll /test drwxr-xr-x 2 test users qa/

Use sticky bit setguid (an s attribute) attribute on folder. It ensures all new files or folders created in it will inherit it's rights group id. For exmaple:

 mkdir test
 sudo chown jask:root test
 sudo chmod g+s test
 touch test/test_file
 ll test/

 -rw-rw-r-- 1 jask root 0 15. pro 11.46 test_file

Similarly you can use setuid chmod u+s for inheriting owner (uid).

When used not on folders but executables it has different meaning. For more reference use https://en.wikipedia.org/wiki/Setuid

Solved, with "chmod g+s test" and add the user to test group. So anyone who is in the test group inheriting the GID from the top folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM