Show Table of Contents
14.4. 設定例
SELinux でどのように Samba サーバーを補完するのか、Samba サーバーの全機能をどのように管理するのかなど、実践的な例を以下に示します。
14.4.1. 作成したディレクトリーを共有する
新規のディレクトリーを作成し、そのディレクトリーを Samba で共有します。
- samba、samba-common、samba-client の各パッケージがインストールされていることを確認します。
~]$
rpm -q samba samba-common samba-clientpackage samba is not installed package samba-common is not installed package samba-client is not installed上記のパッケージがインストールされていない場合は、root でyumユーティリティーを使用して、これらをインストールします。~]#
yum install package-name - root で
mkdirを使用して、Samba 経由でファイルを共有するための最上位の新規ディレクトリーを作成します。~]#
mkdir /myshare - root で
touchユーティリティーを使用して空のファイルを作成します。このファイルは後で Samba 共有が正しくマウントされたかを確認する際に使用します。~]#
touch /myshare/file1 - SELinux では、
/etc/samba/smb.confファイルおよび Linux パーミッションが適切に設定されていれば、Samba はsamba_share_tタイプのラベルが付いたファイルの読み取りおよび書き込みが可能になります。root で以下のコマンドを実行し、ファイルコンテキスト設定にラベルの変更を追加します。~]#
semanage fcontext -a -t samba_share_t "/myshare(/.*)?" - root で
restoreconユーティリティーを使用してラベル変更を適用します。~]#
restorecon -R -v /mysharerestorecon reset /myshare context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0 restorecon reset /myshare/file1 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0 - root で
/etc/samba/smb.confファイルを編集します。Samba で/myshare/ディレクトリーを共有するために、以下をこのファイルの末尾に追加します。[myshare] comment = My share path = /myshare public = yes writable = no
- Samba ファイルシステムのマウントには Samba アカウントが必要になります。root で以下のコマンドを実行し、Samba アカウントを作成します。username は既存の Linux ユーザーにします。たとえば、
smbpasswd -a testuserを実行すると、Linux のtestuserユーザー用の Samba アカウントが作成されます。~]#
smbpasswd -a testuserNew SMB password: Enter a password Retype new SMB password: Enter the same password again Added user testuser.上記のコマンドを実行する際に、システムに存在しないアカウントのユーザー名を指定すると、Cannot locate Unix account for 'username'!エラーが発生します。 - Samba サービスを開始します。
~]#
systemctl start smb.service - 以下のコマンドを実行し、利用可能な共有を表示します。username はステップ 7 で追加した Samba アカウントにします。パスワード入力を求められたら、ステップ 7 で Samba アカウントに割り当てたパスワードを入力します (バージョン番号は使用しているバージョンによって異なります)。
~]$
smbclient -U username -L localhostEnter username's password: Domain=[HOSTNAME] OS=[Unix] Server=[Samba 3.4.0-0.41.el6] Sharename Type Comment --------- ---- ------- myshare Disk My share IPC$ IPC IPC Service (Samba Server Version 3.4.0-0.41.el6) username Disk Home Directories Domain=[HOSTNAME] OS=[Unix] Server=[Samba 3.4.0-0.41.el6] Server Comment --------- ------- Workgroup Master --------- ------- - root で
mkdirユーティリティーを使って新規ディレクトリーを作成します。このディレクトリーは Samba 共有のmyshareをマウントする際に使用します。~]#
mkdir /test/ - root で以下のコマンドを実行して、Samba 共有の
myshareを/test/にマウントします。username はステップ 7 のユーザー名にしてください。~]#
mount //localhost/myshare /test/ -o user=usernameステップ 7 で設定した username のパスワードを入力します。 - 以下のコマンドを実行して ステップ 3 で作成した
file1を表示します。~]$
ls /test/file1
14.4.2. web サイトを共有する
/var/www/html/ ディレクトリーで web サイトを共有したい場合などは、ファイルに samba_share_t タイプのラベルが付けられないことがあります。このような場合には、samba_export_all_ro ブール値を使用して読み取り専用パーミッションを付与して (現在のラベルに関係なく) すべてのファイルやディレクトリーを共有するか、samba_export_all_rw を使用して読み取りおよび書き込みパーミッションを付与して (現在のラベルに関係なく) すべてのファイルやディレクトリーを共有します。
以下の例では、
/var/www/html/ 内に web サイトのファイルを作成してから、そのファイルに読み取りおよび書き込みパーミッションを与えて Samba で共有します。ここでは、httpd、samba、samba-common、samba-client、wget のパッケージがインストールされていることを前提としています。
- root ユーザーで
/var/www/html/file1.htmlファイルを作成します。以下のコンテンツをコピーしてこのファイルに貼り付けます。<html> <h2>File being shared through the Apache HTTP Server and Samba.</h2> </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このファイルにはhttpd_sys_content_tタイプのラベルが付けられています。デフォルトでは、Apache HTTP Server はこのタイプにアクセスできますが、Samba はアクセスできません。 - Apache HTTP Server を起動します。
~]#
systemctl start httpd.service - ユーザーでの書き込みアクセスがあるディレクトリーに切り替え、以下のコマンドを実行します。デフォルト設定に変更がなければ、このコマンドは成功します。
~]$
wget http://localhost/file1.htmlResolving 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 writable = no
/var/www/html/ディレクトリーにはhttpd_sys_content_tタイプのラベルが付けられています。Samba はデフォルトでは、このタイプのラベルが付いたファイルやディレクトリーには、Linux パーミッションで許可されていてもアクセスできません。Samba のアクセスを許可するには、samba_export_all_roブール値を有効にします。~]#
setsebool -P samba_export_all_ro on再起動後に変更を維持したくない場合は、-Pを使用しないでください。samba_export_all_roブール値を有効にすると、Samba からいずれのタイプにもアクセスもできるようになることに注意してください。- Samba サービスを開始します。
~]#
systemctl start smb.service

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.