
特定のグループへの書き込みアクセスを許可するには、そのグループの全員をデフォルトで共有ファイル/フォルダに書き込むように設定し、所有グループをそのグループを所有するグループに自動的に固定できます。親ディレクトリこのディレクトリにsetgidビットを設定すると、次のようになります。
chmod g+s our_shared_directory
それ以外の場合は、ファイル作成者のデフォルトグループが使用されます(通常はユーザー名と同じ)。
上記の引用は、以下に由来しています。Arch Linux Wiki。共有ファイルとフォルダの作成方法がわかりません。ユーザーと言ってくださいㅏそして第二どちらも共通グループに属するG。今、our_shared_directory
誰にとっても基本的にこれをどのように生成しますか?G書き込み権限がありますか?
setgid
第二に、なぜオンが必要ですかour_shared_directory
?なぜ私が属するグループを固定する必要がありますか?親ディレクトリのour_shared_directory
?
答え1
フォルダコントロールを共有したい場合
- ユーザー
a
- ユーザー
b
ユーザーの作成
% 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