4.4.2. web サイトを共有する
/var/www/html/
で web サイトを共有したい場合など、ファイルに samba_share_t
タイプのラベルが付けられない場合があります。 このような場合には、 すべてのファイルやディレクトリを共有するよう samba_export_all_ro
Boolean を使用して読み取り専用パーミッションを付与するか (現在のラベルに関わらず)、 samba_export_all_rw
Boolean を使用して読み取りと書き込みのパーミッションを付与します (現在のラベルに関わらず)。
以下の例では、
/var/www/html/
内に web サイトのファイルを作成してから、 そのファイルを Samba で共有し読み取りと書き込みのパーミッションを与えています。 ここでは、 httpd、 samba、 samba-common、 samba-client、 wget のパッケージがインストールされていることを前提としています。
- root ユーザーになり
/var/www/html/file1.html
ファイルを作成します。 次のコンテンツをコピーして/var/www/html/file1.html
に貼り付けます。<html> <h2>File being shared through the Apache HTTP Server and Samba.</h2> </html>
ls -Z /var/www/html/file1.html
を実行してfile1.html
の SELinux コンテキストを表示させます。$ ls -Z /var/www/html/file1.html -rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/file1.html
file1.index.html
にはhttpd_sys_content_t
タイプのラベルが付けられています。デフォルトでは、Apache HTTP Server によるアクセスはできますが、 Samba によるアクセスはできません。- root ユーザーで
service httpd start
を実行して Apache HTTP Server を起動します。service httpd start Starting httpd: [ OK ]
- Linux ユーザーでの書き込みアクセスがあるディレクトリに移動し、
wget http://localhost/file1.html
コマンドを実行します。 デフォルト設定に変更がなければ、 このコマンドは成功します。$ wget http://localhost/file1.html Resolving localhost... 127.0.0.1 Connecting to localhost|127.0.0.1|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 84 [text/html] Saving to: `file1.html.1' 100%[=======================>] 84 --.-K/s in 0s `file1.html.1' saved [84/84]
- root ユーザーで
/etc/samba/smb.conf
を編集します。 Samba で/var/www/html/
ディレクトリを共有するため、 以下をこのファイルの末尾に追加します。[website] comment = Sharing a website path = /var/www/html/ public = no writeable = no
/var/www/html/
ディレクトリにはhttpd_sys_content_t
タイプのラベルが付けられます。 デフォルトでは、httpd_sys_content_t
タイプのラベルの付いたファイルやディレクトリには、 Linux パーミッションが付与されていても Samba からはアクセスできません。 Samba によるアクセスを許可するため、 root ユーザーで次のコマンドを実行し、samba_export_all_ro
Boolean をオンにします。setsebool -P samba_export_all_ro on
再起動後、この変更を維持したくない場合は-P
を使用しないでください。samba_export_all_ro
Boolean をオンにすると、Samba からはいずれのタイプにもアクセスもできるようになるため注意してください。- root ユーザーで
service smb start
を実行してsmbd
を起動します。service smb start Starting SMB services: [ OK ]