Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

14.4. 設定例

以下の例は、SELinux が Samba サーバーを補完する方法と、Samba サーバーの完全な機能を維持する方法の実例を紹介します。

14.4.1. 作成したディレクトリーの共有

以下の例では、新しいディレクトリーを作成し、Samba でそのディレクトリーを共有します。
  1. samba パッケージ、samba-common パッケージ、および samba-client パッケージがインストールされていることを確認します。
    ~]$ rpm -q samba samba-common samba-client
    package samba is not installed
    package samba-common is not installed
    package samba-client is not installed
    
    これらのパッケージがいずれもインストールされていない場合は、root で yum ユーティリティーを使用してパッケージをインストールします。
    ~]# yum install package-name
  2. mkdir ユーティリティーを root で使用し、Samba でファイルを共有するための新しいトップレベルディレクトリーを作成します。
    ~]# mkdir /myshare
  3. touch ユーティリティーの root を使用して、空のファイルを作成します。このファイルは、後で Samba 共有が正しくマウントされたことを確認するために使用されます。
    ~]# touch /myshare/file1
  4. /etc/samba/smb.conf ファイルおよび Linux のパーミッションが設定されていれば、samba_share_t タイプでラベル付けされたファイルの読み取りと書き込みが可能になります。root で以下のコマンドを入力し、ラベルの変更を file-context 設定に追加します。
    ~]# semanage fcontext -a -t samba_share_t "/myshare(/.*)?"
  5. restorecon ユーティリティーを root で使用し、ラベルの変更を適用します。
    ~]# restorecon -R -v /myshare
    restorecon 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
    
  6. root で/etc/samba/smb.conf を編集します。このファイルの下部に以下を追加し、Samba で/myshare/ ディレクトリーを共有します。
    [myshare]
    comment = My share
    path = /myshare
    public = yes
    writable = no
    
  7. Samba ファイルシステムをマウントするには、Samba アカウントが必要です。root で次のコマンドを入力して、Samba アカウントを作成します。username は、既存の Linux ユーザーです。たとえば、smbpasswd -a testuser は、Linux testuser ユーザーの Samba アカウントを作成します。
    ~]# smbpasswd -a testuser
    New SMB password: Enter a password
    Retype new SMB password: Enter the same password again
    Added user testuser.
    
    上記のコマンドを入力し、システムに存在しないアカウントのユーザー名を指定すると、Cannot locate Unix account for 'username'! エラーが発生します。
  8. Samba サービスを再起動します。
    ~]# systemctl start smb.service
  9. 利用可能な共有を一覧表示するには、次のコマンドを入力します。username は、手順 7 で追加した Samba アカウントです。パスワードを求められたら、手順 7 で Samba アカウントに割り当てたパスワードを入力します (バージョン番号は異なる場合があります)。
    ~]$ smbclient -U username -L localhost
    Enter 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
    ---------            -------
    
  10. mkdir ユーティリティーを root で実行して、新しいディレクトリーを作成します。このディレクトリーは、myshareの Samba 共有をマウントするために使用されます。
    ~]# mkdir /test/
  11. root で次のコマンドを入力して、myshareの Samba 共有を /test/ にマウントし、username を、手順 7 のユーザー名に置き換えます。
    ~]# mount //localhost/myshare /test/ -o user=username
    手順 7 で設定した username のパスワードを入力します。
  12. 手順 3 で作成したfile1 を表示する場合は、以下を実行します。
    ~]$ ls /test/
    file1