为了允许对特定组的写访问,共享文件/文件夹可以默认为该组中的每个人写,并且拥有组可以通过设置此目录上的setgid位自动固定到拥有父目录的组:
chmod g+s our_shared_directory,否则将使用文件创建者的默认组(通常与用户名相同)。
以上报价来自Arch Linux Wiki。我不清楚如何创建共享的文件和文件夹。假设用户A和B都属于一个公共组G,那么现在我如何创建our_shared_directory,这样在默认情况下G中的每个人都有写权限?
第二,为什么我需要setgid on our_shared_directory?为什么我需要将拥有的组固定到our_shared_directory的父目录的组?
发布于 2016-02-29 08:00:12
如果要共享文件夹的控件,请在
ab创建用户
% sudo adduser a
Adding user `a' ...
Adding new group `a' (1002) ...
Adding new user `a' (1001) with group `a' ...
Creating home directory `/home/a' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
....和
% sudo adduser b
Adding user `b' ...建立一个目录
% mkdir our_shared_directory创建一个新组并将用户添加到其中
% sudo addgroup cool_kids
Adding group `cool_kids' (GID 1001) ...
Done.
% sudo adduser a cool_kids
Adding user `a' to group `cool_kids' ...
Adding user a to group cool_kids
Done.
% sudo adduser b cool_kids
....使目录属于cool_kids组和setgid位
sudo chmod g+s our_shared_directory
sudo chown -v ubuntu:cool_kids our_shared_directory检查我们的工作
ls -al
drwxrwsr-x 2 ubuntu cool_kids 40 Feb 29 20:37 our_shared_directory/
^ setgid bit is set and group is now "sticky" 查看由用户a在普通目录中生成文件时发生的情况。
% touch file_made_by_user_a
% ls -al
-rw-rw-r-- 1 a a 0 Feb 29 20:57 file_made_by_a现在,用户a在our_shared_directory中创建一个文件
% cd our_shared_directory/
% ls -al
-rw-rw-r-- 1 a cool_kids 0 Feb 29 20:59 another_by_a
^^^^^^ note the group 现在切换到用户b
% su b
Password: ...B现在可以编辑a-因为another_by_a文件的默认模式是-rw-rw-r--,所以b通常不能编辑它。
但与
b% vim another_by_a
^ note this means we are user "b" now
[make some edit and save]b能够修改文件**,因为b属于cool_kids组,而且cool_kids被setgid比特保证应用到新文件中。
ls -al
-rw-rw-r-- 1 a cool_kids 7 Feb 29 21:03 another_by_a
^ the file is 7bytes - slightly bigger because of changes made by b https://unix.stackexchange.com/questions/266436
复制相似问题