SAMBA設定 · 5 min read · Oct 06, 2025

Mandriva Directory Server On Debian Etch - Page 2

5 SAMBA

5.1 基本設定

まず、SAMBAを停止します。

/etc/init.d/samba stop

例のSAMBA設定ファイルをSAMBAディレクトリにコピーします…

cp /usr/share/doc/python-mmc-base/contrib/samba/smb.conf /etc/samba/

… そして、必要に応じて調整します。

vi /etc/samba/smb.conf

[global]セクションに次の値を設定します:

workgroup = EXAMPLE
netbiosname = PDC-SRV-EXAMPLE
ldap admin dn = cn=admin,dc=example,dc=com
ldap suffix = dc=example,dc=com
logon path = \%N\profiles\%U

[global]セクションに次の行を追加します:

preferred master = yes
os level = 65
wins support = yes
timeserver = yes
socket options = SO_KEEPALIVE IPTOS_LOWDELAY SO_SNDBUF=8192 SO_RCVBUF=8192
logon drive = H:
passwd program = /usr/sbin/smbldap-passwd -u %u
passwd chat = “Changing password for\nNew password“ %n\n “Retype new password“ %n\n
add user script = /usr/sbin/smbldap-useradd -m “%u”
add user to group script = /usr/sbin/smbldap-groupmod -m “%u” “%g”
set primary group script = /usr/sbin/smbldap-usermod -g “%g” “%u”
add group script = /usr/sbin/ambldap-groupadd -p “%g”
delete user script = /usr/sbin/smbldap-userdel “%u”
delete user from group script = /usr/sbin/smbldap-groupmod -x “%u” “%g”
delete group script = /usr/sbin/smbldap-groupdel “%g”
obey pam restrictions = no
ldap idmap suffix = ou=Users
ldap delete dn = yes
security = user

[homes]セクションに次の行を追加します:

hide files = /Maildir/

[printers]および[print$]セクションから次の行を削除します:

printer admin = root,@lpadmin

[print$]セクションに次の値を設定します:

write list = Administrator,root,@lpadmin

[profiles]セクションに次の行を追加します:

hide files = /desktop.ini/ntuser.ini/NTUSER.*/

[archives]セクションに次の値を設定します:

path = /home/samba/archives

この時点で、SAMBA設定ファイルは次のようになります:

     [global]
        workgroup = EXAMPLE
        netbiosname = PDC-SRV-EXAMPLE
        preferred master = yes
        os level = 65
        wins support = yes
        enable privileges = yes
        timeserver = yes
        socket options = SO_KEEPALIVE IPTOS_LOWDELAY SO_SNDBUF=8192 SO_RCVBUF=8192
        log level = 3
        null passwords = yes
        security = user
        # unix charset = ISO8859-1
        name resolve order = bcast host
        domain logons = yes
        domain master = yes
        printing = cups
        printcap name = cups
        logon path = \\%N\profiles\%U
        logon script = logon.bat
        logon drive = H:
        map acl inherit = yes
        nt acl support = yes
        passdb backend = ldapsam:ldap://127.0.0.1/
        obey pam restrictions = no  

        ldap admin dn = cn=admin,dc=example,dc=com
        ldap suffix = dc=example,dc=com
        ldap group suffix = ou=Groups
        ldap user suffix = ou=Users
        ldap machine suffix = ou=Computers
        ldap idmap suffix = ou=Users
        ldap passwd sync = yes
        ldap delete dn = yes  

        passwd program = /usr/sbin/smbldap-passwd -u %u
        passwd chat = "Changing password for*\nNew password*" %n\n "*Retype new password*" %n\n
         
    add user script = /usr/sbin/smbldap-useradd -m "%u"
        add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
        set primary group script = /usr/sbin/smbldap-usermod -g "%g" "%u"
        add group script = /usr/sbin/ambldap-groupadd -p "%g"
        add machine script = /usr/lib/mmc/add_machine_script '%u'
        delete user script = /usr/sbin/smbldap-userdel "%u"
        delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
        delete group script = /usr/sbin/smbldap-groupdel "%g"  

     [homes]
        comment = ホームディレクトリ
        browseable = no
        writeable = yes
        create mask = 0700
        directory mask = 0700
    hide files = /Maildir/  

     [public]
        comment = 公開共有
        path = /home/samba/shares/public
        browseable = yes
        public = yes
        writeable = yes  

     [archives]
        comment = バックアップ共有
        path = /home/samba/archives
        browseable = yes
        public = no
        writeable = no  

     [printers]
        comment = プリンタ
        path = /tmp
        browseable = no
        public = yes
        guest ok = yes
        writeable = no
        printable = yes  

     [print$]
        comment = ドライバ
        path = /var/lib/samba/printers
        browseable = yes
        guest ok = yes
        read only = yes
        write list = Administrator,root,@lpadmin  

     [netlogon]
        path = /home/samba/netlogon
        public = no
        writeable = no
        browseable = no  

     [profiles]
        path = /home/samba/profiles
        writeable = yes
        create mask = 0700
        directory mask = 0700
        browseable = no
        hide files = /desktop.ini/ntuser.ini/NTUSER.*/  

     [partage]
        comment = aucun
        path = /home/samba/partage
        browseable = yes
        public = no
        writeable = yes

すべてが正常に行われた場合、コマンド…

testparm

…はエラーを返さないはずです。

次に、LDAPに書き込むために必要な資格情報をSAMBAに与えます。

smbpasswd -w %ldap_admin_password%

例えば:

smbpasswd -w howtoforge

出力は次のようになります:

"cn=admin,dc=example,dc=com"のために秘密を設定しています secrets.tdb

次に、ワークグループのSIDを作成する必要があります。

net getlocalsid %your_workgroup%

例えば:

net getlocalsid EXAMPLE

出力は次のようになります - メモしておいてください、すぐに必要になります:

ドメインEXAMPLEのSIDは:S-1-5-21-3159899821-123882392-54881133

SIDが本当にLDAPに記録されているか確認します。

slapcat | grep sambaDomainName

出力は次のようになります:

dn: sambaDomainName=EXAMPLE,dc=example,dc=com  
sambaDomainName: EXAMPLE

今、SAMBAを起動します。

/etc/init.d/samba start

5.2 LDAPディレクトリ

最初に、smbldap-tools設定ファイルを作成する必要があります - これはLDAPサーバーとの通信方法を定義します。

vi /etc/smbldap-tools/smbldap_bind.conf

内容は次のようになります:

slaveDN="cn=admin,dc=example,dc=com"
slavePw="howtoforge"
masterDN="cn=admin,dc=example,dc=com"
masterPw="howtoforge"

次に、メイン設定ファイルを作成します。

vi /etc/smbldap-tools/smbldap.conf

内容は次のようになります(SIDは自分のものに置き換えてください!):

SID="S-1-5-21-3159899821-123882392-54881133"
sambaDomain="EXAMPLE"
ldapTLS="0"
suffix="dc=example,dc=com"
usersdn="ou=Users,${suffix}"
computersdn="ou=Computers,${suffix}"
groupsdn="ou=Groups,${suffix}"
idmapdn="ou=Idmap,${suffix}"
sambaUnixIdPooldn="sambaDomainName=EXAMPLE,${suffix}"
scope="sub"
hash_encrypt="SSHA"
userLoginShell="/bin/bash"
userHome="/home/%U"
userHomeDirectoryMode="700"
userGecos="System User"
defaultUserGid="513"
defaultComputerGid="515"
skeletonDir="/etc/skel"
defaultMaxPasswordAge="45"
userSmbHome="\\PDC-SRV-EXAMPLE\%U"
userProfile="\\PDC-SRV-EXAMPLE\profiles\%U"
userHomeDrive="H:"
userScript="logon.bat"
mailDomain="example.com"
smbpasswd="/usr/bin/smbpasswd"

LDAPディレクトリをポピュレートする時間です。これにより、ドメイン管理者アカウント(Administrator)も作成されます。

smbldap-populate -m 512 -a Administrator

注意:ドメイン管理者アカウントのパスワードを入力するように求められます。

その後、このアカウントのuid番号を変更する必要があります - そうしないと、このアカウントでメールサーバーを使用できません。さらに、このアカウントを「Domain Users」グループに追加します:

smbldap-usermod -u 3000 -G "Domain Users" Administrator

5.3 NSS LDAP設定

このステップでは、システムをLDAPディレクトリを使用してユーザーおよびグループリストを取得するように設定します。

nsswitch設定を編集します。

vi /etc/nsswitch.conf

内容は次のようになります:

# /etc/nsswitch.conf
#
# GNU Name Service Switch機能の例の設定。
# `glibc-doc'および`info'パッケージがインストールされている場合は、次を試してください:
# `info libc "Name Service Switch"'このファイルに関する情報。
passwd:         compat ldap
group:          compat ldap
shadow:         compat ldap
hosts:          files dns
networks:       files
protocols:      db files
services:       db files
ethers:         db files
rpc:            db files
netgroup:       nis

5.4 SAMBAディレクトリ

SAMBAサーバーに必要なディレクトリを作成します…

mkdir -p /home/samba/shares/public/  
mkdir /home/samba/netlogon/  
mkdir /home/samba/profiles/  
mkdir /home/samba/partage/  
mkdir /home/samba/archives/

… 所有権を変更し、権限を調整します。

chown -R :"Domain Users" /home/samba/  
chmod 777 /var/spool/samba/ /home/samba/shares/public/  
chmod 755 /home/samba/netlogon/  
chmod 770 /home/samba/profiles/ /home/samba/partage/  
chmod 700 /home/samba/archives/

6 PAM LDAP設定

このステップでは、PAMにLDAPサポートを追加します。

vi /etc/pam.d/common-account

内容は次のようになります:

#
# /etc/pam.d/common-account - すべてのサービスに共通する認可設定
#
# このファイルは他のサービス固有のPAM設定ファイルから含まれ、
# システムで使用する中央アクセスポリシーを定義する認可モジュールのリストを含む必要があります。
# デフォルトは、/etc/shadowでアカウントが期限切れのユーザーにサービスを拒否することだけです。
#
account required        pam_unix.so
account sufficient      pam_ldap.so
vi /etc/pam.d/common-auth

内容は次のようになります:

#
# /etc/pam.d/common-auth - すべてのサービスに共通する認証設定
#
# このファイルは他のサービス固有のPAM設定ファイルから含まれ、
# システムで使用する中央認証スキームを定義する認証モジュールのリストを含む必要があります
# (例:/etc/shadow、LDAP、Kerberosなど)。デフォルトは、
# 従来のUnix認証メカニズムを使用します。
#
auth    sufficient      pam_unix.so nullok_secure
auth    sufficient      pam_ldap.so use_first_pass
auth    required        pam_deny.so
vi /etc/pam.d/common-password

内容は次のようになります:

#
# /etc/pam.d/common-password - すべてのサービスに共通するパスワード関連モジュール
#
# このファイルは他のサービス固有のPAM設定ファイルから含まれ、
# ユーザーのパスワードを変更するために使用されるサービスを定義するモジュールのリストを含む必要があります。
# デフォルトはpam_unixです
# "nullok"オプションは、ユーザーが空のパスワードを変更できるようにします。そうでない場合、
# 空のパスワードはロックされたアカウントとして扱われます。
#
# (モジュール名の後に`md5'を追加してMD5パスワードを有効にします)
#
# "obscure"オプションは、古い`OBSCURE_CHECKS_ENAB'オプションを置き換えます
# login.defs。さらに、"min"および"max"オプションは、新しいパスワードの長さを強制します。
password        sufficient      pam_unix.so nullok obscure min=4 max=8 md5
password        sufficient      pam_ldap.so use_first_pass use_authtok
password        required        pam_deny.so
# パスワードの強度チェックの代替。これは、
# libpam-cracklibパッケージがインストールされている必要があります。
# 上記のパスワード行をコメントアウトし、
# 使用するために次の2つの行のコメントを外す必要があります。
# (古い`OBSCURE_CHECKS_ENAB'、`CRACKLIB_DICTPATH'を置き換えます)
#
# password required       pam_cracklib.so retry=3 minlen=6 difok=3
# password required       pam_unix.so use_authtok nullok md5
vi /etc/pam.d/common-session

内容は次のようになります:

#
# /etc/pam.d/common-session - すべてのサービスに共通するセッション関連モジュール
#
# このファイルは他のサービス固有のPAM設定ファイルから含まれ、
# すべての種類のセッション(対話型および非対話型)の開始と終了時に実行されるタスクを定義するモジュールのリストを含む必要があります。
# デフォルトはpam_unixです。
#
session required        pam_unix.so
session optional        pam_ldap.so

その後、システムを再起動します。

reboot

システムが再起動したら、「Domain Admins」グループにドメインにマシンを追加する権利を与えます。

net -U Administrator rpc rights grant 'DOMAIN\Domain Admins' SeMachineAccountPrivilege

7 メール用のSSL

まず、必要な情報を含む設定ファイルを準備します。

vi /etc/ssl/mail.cnf

次の内容を追加します:

[ req ] 
default_bits            = 2048 
default_keyfile         = privkey.pem 
distinguished_name      = req_distinguished_name 
prompt                  = no 
string_mask             = nombstr 
x509_extensions         = server_cert
[ req_distinguished_name ] 
countryName             = DE 
stateOrProvinceName     = Niedersachsen
localityName            = Lueneburg
organizationName        = Projektfarm GmbH
organizationalUnitName  = IT
commonName              = server1.example.com
emailAddress            = [email protected]
[ server_cert ] 
basicConstraints        = critical, CA:FALSE 
subjectKeyIdentifier    = hash 
keyUsage                = digitalSignature, keyEncipherment 
extendedKeyUsage        = serverAuth, clientAuth 
nsCertType              = server 
nsComment               = "mailserver"

次に、SSL証明書を作成します…

openssl req -x509 -new -config /etc/ssl/mail.cnf -out /etc/ssl/certs/mail.pem -keyout /etc/ssl/private/mail.key -days 365 -nodes -batch

… そして、キーの権限を調整して、rootのみが読み取れるようにします。

chmod 600 /etc/ssl/private/mail.key
Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。