Samba をスタンドアローンサーバーとして構成

提供: 雑廉堂Wiki

はじめに

ホームネットワークのような小規模なネットーワークや、ドメインの一部ではないホスト上のフォルダ等を共有するために Active DirectoryNT4 Domain を設定したくない場合がよくあります。

下に続く文書では Samba スタンドアローンサーバー のセットアップ方法について説明します。

  • 匿名でアクセス可能な共有 (ゲストアクセス)
  • Samba ホストのユーザーデータベースに対する認証を必要とする共有

基本的なゲスト専用の smb.conf ファイルの作成

以下は、ゲストアクセスのみを許可する Samba スタンドアローンサーバーの最小構成です。

[global]
        map to guest = Bad User
        log file = /var/log/samba/%m
        log level = 1

[guest]
        # This share allows anonymous (guest) access
        # without authentication!
        path = /srv/samba/guest/
        read only = no
        guest ok = yes
        guest only = yes

smb.conf ファイルで基本の認証されたアクセスを作成する

The following is a minimal configuration for a Samba standalone server:

Samba スタンドアローンサーバーの最小構成を以下に示します:

[global]
        log file = /var/log/samba/%m
        log level = 1

[demo]
        # This share requires authentication to access
        path = /srv/samba/demo/
        read only = no
  • workgroup = xxxxxxxx でワークグループ名を設定することができます。'xxxxxxxx' は必須です。もしパラメータが設定されていない場合、規定のワークグループ名として 'WORKGROUP' が使用されます。
  • 最小構成ではログのパラメータは必須ではありません。しかしながら、問題が発生した場合にログファイルを設定し、ログレベルを上げると役立ちます。
  • 上記は最小限の smb.conf ファイルですが、Unix と Samba の同期が維持されているかを確認することができる 'unix password sync = yes' のような他のパラメータを追加することができます。詳細は 'man smb.conf' を参照してください。



ローカルユーザーアカウントの作成

スタンドアローンホストで認証を提供するには、オペレーティングシステムでローカルに加えて、Samba データベースにアカウントを作成する必要があります。Samba は tdbsam バックエンドを使用して、/usr/local/samba/private/passdb.tdb ファイルにデータベースを保存します。任意で、smb.conf 内で passdb backend パラメータを使用して別の場所を設定することができます。詳細は smb.conf 5 のマニュアルページを参照してください。


  • ローカルシステムに demoUser アカウントを作成
# useradd -M -s /sbin/nologin demoUser
もし、このホストでユーザーのホームディレクトリが必要な場合は、-Mパラメータを省略してください。Samba がアクセスするのには、アカウントに有効なシェルは必要ありません。


  • ローカルシステムで demoUser アカウントを有効にする。
# passwd demoUser
Enter new UNIX password: Passw0rd
Retype new UNIX password: Passw0rd
passwd: password updated successfully
アカウントを有効にするには、ローカルパスワードを設定することは必須です。Samba はローカルで無効にされたアカウントのアクセスを拒否します。もし、有効なシェルを使わずにアカウントを作成した場合、このパスワードを使用したログインは不可能になります。
  • demoUser アカウント Samba データベースに追加します
# smbpasswd -a demoUser
New SMB password: Passw0rd
Retype new SMB password: Passw0rd
Added user demoUser.
この手順で割り当てられるパスワードは、ドメインにログインするためにユーザーが使用するパスワードです。

ローカルグループの管理

  • demoGroup グループを作成するには:
# groupadd demoGroup
  • demoUser アカウントをグループに追加するには:
# usermod -aG demoGroup demoUser

共有ディレクトリの作成

共有ディレクトリを作成:

# mkdir -p /srv/samba/guest/
# mkdir -p /srv/samba/demo/

共有ディレクトリに ACL を設定する

以下の POSIX パーミッションを設定します:

# chgrp -R demoGroup /srv/samba/guest/
# chgrp -R demoGroup /srv/samba/demo/

# chmod 2775 /srv/samba/guest/
# chmod 2770 /srv/samba/demo/

これは、 demoGroup グループのメンバーに、両方のディレクトリの書込みアクセスを構成します。他のユーザーは、/srv/samba/guest/ に読込アクセス権を持っており、/srv/samba/demo/ ディレクトリにはなんの権限も持っていません。ディレクトリにセットされているモードの最初のビット - (2) で表されている - SGID ビットは、ファイル作成時に、ユーザーのプライマリグループでセットする代わりに親ディレクトリのグループを引き継いでセットします。

詳細な情報については、Setting up a Share Using POSIX ACLs を参照してください。

Starting Samba

Start the smbd daemon:

# smbd

Samba does not include start scripts. See your distribution's documentation how further information how to automatically start a service at boot time.



Testing the Share Access

  • Access the demo share as user demoUser:
# smbclient -U demoUser //SA/demo
Enter demoUser's password: Passw0rd
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba x.y.z]
smb: \> ls
  .                                   D        0  Sun Jan  3 21:00:00 2016
  ..                                  D        0  Sun Jan  3 19:00:00 2016
  demo.txt                            A        0  Sun Jan  3 21:00:00 2016

		9943040 blocks of size 1024. 7987416 blocks available
smb: \> quit
  • Access the demo share as guest. The access is denied:
# smbclient -U guest //SA/demo
Enter guest's password: 
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba x.y.z]
tree connect failed: NT_STATUS_ACCESS_DENIED



Advanced share settings

This section describes some advanced share configuration parameters. For further information about the used parameters, see the smb.conf (5) man page.


Using the force Parameters

[demo]
        path = /srv/samba/demo/
        read only = no
        force create mode = 0660
        force directory mode = 2770
        force user = demoUser
        force group = demoGroup

The force create mode and force directory mode parameters force Samba to create new files and folders with the set permissions.

The force user and force group parameters map all connections to the specified user and group. Note that this can cause security problems if all users connecting to a share are mapped to a specific user account or group in the background.


User and Group-based Share Access

See Configuring User and Group-based Share Access.


Host-based Share Access

See Configuring Host-based Share Access.