差分

ユーザ権限とアクセス制御

2,071 バイト追加, 2018年12月14日 (金) 02:10
/* ディレクトリにsetgidビットを設定する */
apache apache /usr/sbin/httpd
</pre>
 
== ディレクトリへの特殊な設定 ==
=== ディレクトリにsetgidビットを設定する ===
 
ディレクトリのグループにsetgidビットを設定すると、そのディレクトリ以下に作られるファイル及びディレクトリには現ディレクトリのグループが適用されます。
 
<pre class="bash">
$ ls -l
合計 4
drwxrwx--- 2 hironobu hironobu 4096 12月 14 02:35 foo
$ sudo touch foo/fileA
$ ls -al foo
合計 8
drwxrwx--- 2 hironobu hironobu 4096 12月 14 02:36 .
drwxrwx--- 3 hironobu hironobu 4096 12月 14 02:35 ..
-rw-r----- 1 root root 0 12月 14 02:36 fileA
</pre>
 
この例は、fooというディレクトリがあり、そのディレクトリ下にコマンド touch を使いrootの持ち物である fileA を作成します。
この時のfileAの所有者、グループともrootです。
 
 
<pre class="bash">
$ chmod g+s foo
$ ls -ld foo
drwxrws--- 2 hironobu hironobu 4096 12月 14 02:36 foo
$ sudo touch foo/fileB
$ ls -al foo
合計 8
drwxrws--- 2 hironobu hironobu 4096 12月 14 02:37 .
drwxrwx--- 3 hironobu hironobu 4096 12月 14 02:35 ..
-rw-r----- 1 root root 0 12月 14 02:36 fileA
-rw-r----- 1 root hironobu 0 12月 14 02:37 fileB
</pre>
 
ディレクトリ foo に対しsetgid ビットの設定を行います。setgid ビットがセットされるとグループの"x"だった部分が"s"に変化します。
次にコマンド touch で fileB を作成します。
ディレクトリのグループ hironobu がファイルに継承されて fileB の所有者は root グループが hironobu になります。
 
=== ディレクトリにStickyビットを設定する ===
 
ユーザ(user)が読み書きできるディレクトリにStickyビットを設定した場合、そのディレクトリにどのユーザでもファイルを作成することができますが、ディレクトリから削除する場合、そのファイルの所有者(owner)しか削除できません。
 
<pre class="bash">
$ mkdir temp
$ ls -dl temp
drwxr----- 2 hironobu hironobu 4096 12月 14 03:12 temp
$ chmod go+rwxt temp
$ ls -dl temp
drwxrwxrwt 2 hironobu hironobu 4096 12月 14 03:12 temp
</pre>
 
== ACL ==
<syntaxhighlight langpre class="bash">
$touch foo.txt
$ ls -l foo.txt
-rw-rw-r-- 1 hironobu hironobu 0 Aug 31 08:15 foo.txt
</syntaxhighlightpre>
<syntaxhighlight langpre class="bash">
$ getfacl foo.txt
# file: foo.txt
group::rw-
other::r--
</syntaxhighlightpre>
<syntaxhighlight langpre class="bash">
$ chmod go-rw foo.txt
$ ls -l foo.txt
-rw------- 1 hironobu hironobu 0 Aug 31 08:15 foo.txt
</syntaxhighlightpre>
<syntaxhighlight langpre class="bash">
$ setfacl -m user:www-data:r foo.txt
</syntaxhighlightpre>
<syntaxhighlight langpre class="bash">
$ getfacl foo.txt
# file: foo.txt
mask::r--
other::---
</syntaxhighlightpre>
<syntaxhighlight langpre class="bash">
% ls -l foo.txt
-rw-r-----+ 1 hironobu hironobu 0 Aug 31 08:15 foo.txt
</syntaxhighlightpre>