Samba/LDAPサーバの構築 (2011/06/21)
転任時のサーバ環境は,LDAPによる認証の統一はされていませんでした.テスト的に,LDAPサーバは構築されていましたが,実際に運用されていませんでした.そのため,新たにSamba/LDAPサーバを構築し直しました.現在,Samba/LDAPサーバを無事運用していますが,LDAPデータベースの変更はコマンドベースは厳しいので,GUIのApache Directory Studioを利用しています.最初の構築イメージでは,LDAPデータベースだけではなくサーバの /etc/passwd にもアカウント登録されるものと思っていましたが,新規アカウントはLDAPデータベースのみに登録されます.Linux も Windows もサーバのLDAPデータベースを参照して,アカウント認証します.Windows の場合は,サーバの Samba 経由での認証になります.サーバのホスト名は,仮に server としています.
LDAPサーバの構築
CentOS 5.6のサーバに,LDAPサーバを構築しました.
- 現在のサービスの停止
現在のサービスを停止します.
root@server# service ldap stop
- パッケージのインストール
関連パッケージがインストールされていなければ,パッケージをインストールします.
root@server# yum -y install openldap openldap-clients openldap-servers root@server# yum -y install cyrus-sasl-md5
- Sambaスキーマのコピー
Sambaスキーマをコピーします.
root@server# cp /usr/share/doc/samba-*/LDAP/samba.schema /etc/openldap/schema/.
- 管理者パスワードの作成
管理者パスワードを作成します.
root@server# slappasswd New password: (管理者パスワードの入力) Re-enter new password: (管理者パスワードの再入力) (管理者のパスワードのハッシュ値)
- slapd.conf の設定
以下に /etc/openldap/slapd.conf の内容を記載します.なお,サーバ固有の情報を表すものは適当に置き替えました.ここでは,cn=manager,dc=example,dc=com としています.cn=replica は将来構築するであろう複製サーバ用です.パスワードなどは自身のものを入れて下さい.
include /etc/openldap/schema/core.schema include /etc/openldap/schema/cosine.schema include /etc/openldap/schema/inetorgperson.schema include /etc/openldap/schema/nis.schema include /etc/openldap/schema/samba.schema allow bind_v2 pidfile /var/run/openldap/slapd.pid argsfile /var/run/openldap/slapd.args access to * by dn="cn=manager,dc=example,dc=com" write by dn="cn=replica,dc=example,dc=com" read by * break access to attrs=userPassword by anonymous auth by self write by * none access to attrs=sambaLMPassword,sambaNTPassword,sambaPasswordHistory by * none access to * by * read database bdb suffix "dc=example,dc=com" rootdn "cn=manager,dc=example,dc=com" rootpw (管理者のパスワードのハッシュ値) directory /var/lib/ldap index objectClass eq,pres index ou,cn,mail,surname,givenname eq,pres,sub index uidNumber,gidNumber,loginShell eq,pres index uid,memberUid eq,pres,sub index nisMapName,nisMapEntry eq,pres,sub
次のコマンドで設定をテストします.root@server# slaptest root@server# service ldap configtest
- ldap.conf の設定
/etc/openldap/ldap.conf に次の項目を追加します.
BASE dc=example,dc=com URI ldap://127.0.0.1 SSL no
- データベース設定ファイルの設置
以前のデータベースは適当なディレクトリに保存してから,データベース設定ファイルを設置します.
root@server# cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG root@server# chgrp ldap /var/lib/ldap/DB_CONFIG
- サービスの起動
LDAPサービスを起動します.
roor@server# service ldap start slapd の設定ファイルをチェック中: config file testing succeeded [ OK ] slapd を起動中: [ OK ]
マシン起動時にLDAPのサービスを開始するように設定します.root@server# chkconfig ldap on root@server# chkconfig --list ldap ldap 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- 基本的なエントリの作成・登録
/root/base.ldif に基本的なエントリを作成します.
# domain dn: dc=example,dc=com objectClass: dcObject objectClass: organization dc: example o: example.com # manager dn: cn=manager,dc=example,dc=com objectClass: organizationalRole cn: Manager description: Directory Manager # people dn: ou=people,dc=example,dc=com objectClass: organizationalUnit ou: people # group dn: ou=group,dc=example,dc=com objectClass: organizationalUnit ou: group
これらの基本的なエントリを登録します.root@server# ldapadd -x -W -D "cn=manager,dc=example,dc=com" -f base.ldif Enter LDAP Password: (パスワードを入力) adding new entry "dc=example,dc=com" adding new entry "cn=manager,dc=example,dc=com" adding new entry "ou=people,dc=example,dc=com" adding new entry "ou=group,dc=example,dc=com"
- 既存の Linux アカウントの登録
従来のサーバの /etc/passwd, /etc/group からLDAPへの登録形式にするために MigrationTools がインストールされているかどうかを確認します.
root@server# rpm -ql openldap-servers | grep migration
/usr/share/openldap/migration/migrate_common.ph の次の項目を修正します.$DEFAULT_MAIL_DOMAIN = "example.com"; $DEFAULT_BASE = "dc=example,dc=com";
Linux のユーザアカウントとグループを抽出します.ここでは,ユーザアカウントの uid は,4, 5桁の数字とし,ユーザアカント以外のアカウントとは区別可能とします.root@server# egrep :[1-9]\{4,5\}: /etc/passwd > linux-user-list root@server# egrep :[1-9]\{4,5\}: /etc/group > linux-group-list
migrate_passwd.pl を実行して,LDAP登録形式を作成します.root@server# /usr/share/openldap/migration/migrate_passwd.pl linux-user-list > linux-user.ldif root@server# /usr/share/openldap/migration/migrate_group.pl linux-group-list > linux-group.ldif
linux-user.ldif と linux-group.ldif を追加します.root@server# ldapadd -f linux-group.ldif -x -D "cn=manager,dc=example,dc=com" -W root@server# ldapadd -f linux-user.ldif -x -D "cn=manager,dc=example,dc=com" -W
- LDAPサーバによるローカルユーザ認証
バッチ処理でローカルユーザ認証としてLDAPを追加するには,次のコマンドを実行します.
root@server# authconfig --enableldap --enableldapauth --ldapserver=127.0.0.1 --ldapbasedn=dc=example,dc=com --update
対話形式で行う場合は次のように行います.root@server# authconfig-tui
Samba PDC (Primary Domain Controller) の構築
Samba のデータベースを tdbsam: から,LDAP の ldapsam: へと変更します.
- 現在の Samba サービスの停止
現在の Samba サービスを停止します.
root@server# service smb stop
- Sambaのインストール †
関連パッケージがインストールされていなければ,インストールします.
root@server# yum -y install samba3x samba3x-client samba3x-common root@server# yum -y install system-config-samba
- smb.conf の設定
/etc/samba/smb.conf の中身を次のように設定します.ここでは,Windows ドメインを仮に EXAMPLE_COM とし,ローカルネットワークのアドレスを 192.168.0.0/255.255.255.0 としています.また,Linux ユーザの所属グループを user とし,マシンの所属グループを computer としています.適宜,置き替えて下さい.
[global] # # Character settings # dos charset = CP932 unix charset = UTF-8 display charset = UTF-8 # # Browsing/Identification # workgroup = EXAMPLE_COM netbios name = server server string = %h local master = yes wins support = no dns proxy = yes time server = no # # PDC settings # domain logons = yes domain master = yes os level = 128 preferred master = yes server schannel = auto # # Authentication # security = user encrypt passwords = yes passdb backend = ldapsam:ldap://127.0.0.1 obey pam restrictions = yes unix password sync = yes pam password change = yes passwd program = /usr/bin/passwd %u passwd chat = *New*password* %n\n *Re*new*password* %n\n *success* username map = /etc/samba/smbusers # # LDAP settings # ldap ssl = off ldap passwd sync = yes ldap delete dn = yes ldap admin dn = cn=manager,dc=example,dc=com ldap suffix = dc=example,dc=com ldap user suffix = ou=Users ldap group suffix = ou=Groups ldap machine suffix = ou=Computers # # UNIX user/group management # add user script = /usr/sbin/smbldap-useradd -g user -m '%u' rename user script = /usr/sbin/smbldap-usermod -r '%unew' '%uold' delete user script = /usr/sbin/smbldap-userdel '%u' set primary group script = /usr/sbin/smbldap-usermod -g '%g' '%u' add group script = /usr/sbin/smbldap-groupadd -p '%g' delete group script = /usr/sbin/smbldap-groupdel '%g' add user to group script = /usr/sbin/smbldap-groupmod -m '%u' '%g' delete user from group script = /usr/sbin/smbldap-groupmod -x '%u' '%g' add machine script = /usr/sbin/smbldap-useradd -g computer -w '%u' # # Logon settings # logon home = \\%L\%U logon path = logon script = logon drive = z: # # Access control # hosts allow = 192.168.0.0/255.255.255.0 # # Debugging/Accounting # log level = 2 log file = /var/log/samba/log.%m max log size = 5000 syslog only = no syslog = 0 # # Printing # load printers = yes printing = cups printcap name = cups printer admin = @admin # # Misc # socket options = TCP_NODELAY dos filetime resolution = yes client ntlmv2 auth = yes [homes] comment = %U's Home Directories read only = no browseable = no create mask = 0644 directory mask = 0755 hide dot files = yes [printers] comment = All Printers path = /var/spool/samba guest only = no printable = yes browseable = no
/etc/samba/smb.conf の書式が問題ないかチェックします.出力された WARNING は無視します.root@server# testparm WARNING: The "printer admin" option is deprecated
以前の tdbsam: のデータベースは適当なディレクトリに保存しておきましょう. - Samba サービスの起動
Samba サービスを起動します.
root@server# service smb start
Samba サービスがサーバ起動時に自動起動するように設定します.root@server# chkconfig smb on root@server# chkconfig --list smb smb 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- LDAPの管理用パスワードの登録
LDAP 管理用のパスワードを Samba に登録します.
root@server# smbpasswd -W Setting stored password for "cn=manager,dc=example,dc=com" in secrets.tdb New SMB password: (LDAPの管理用パスワードを入力) Retype new SMB password: (LDAPの管理用パスワードをもう一度入力)
- データベースの移行 : tdbsam から ldapsam へ
データベース tdbsam: の中身を ldapsam: に移行します.
root@server# pdbedit -i tdbsam -e ldapsam:ldap://127.0.0.1 WARNING: The "printer admin" option is deprecated smbldap_search_domain_info: Searching for:[(&(objectClass=sambaDomain) (sambaDomainName=EXAMPLE_COM))] smbldap_open_connection: connection opened add_new_domain_info: added: domain = ICE_WIN in the LDAP database smbldap_search_domain_info: Searching for:[(&(objectClass=sambaDomain) (sambaDomainName=EXAMPLE_COM))] ...
- smbldap-tools のインストール
Linux と Samba のアカウントとパスワードを統一的に扱う smbldap-tools をインストールします.
root@server# yum -y install smbldap-tools
- smbldap.conf, smbldap_bind.conf の設定
smbldap-tools に含まれる対話型スクリプトにより設定します.
root@server# cd /usr/share/doc/smbldap-tools-0.9.5 root@server# ./configure.pl Samba Configuration File Path [/etc/samba/smb.conf] > Smbldap-tools Configuration Directory Path [/etc/smbldap-tools/] > workgroup name [EXAMPLE_COM] > netbios name [server] > logon drive [z:] > logon home (press the "." character if you don't want homeDirectory) [\\%L\%U] > logon path (press the "." character if you don't want roaming profile) [\\server\profiles\%U] > . home directory prefix (use %U as username) [/home/%U] > default users' homeDirectory mode [700] > 755 default user netlogon script (use %U as username) [] > default password validation time (time in days) [45] > 365 <-- 後でコメントアウト ldap suffix [dc=example,dc=com] > ldap group suffix [ou=Groups] > ldap user suffix [ou=Users] > ldap machine suffix [ou=Computers] > Idmap suffix [ou=Idmap] > sambaUnixIdPooldn object (relative to ${suffix}) [sambaDomainName=EXAMPLE_COM] > ldap master server [127.0.0.1] > ldap master port [389] > ldap master bind dn [cn=manager,dc=example,dc=com] > ldap master bind password [] > (管理者パスワードを入力) ldap slave server [127.0.0.1] > ldap slave port [389] > ldap slave bind dn [cn=manager,dc=example,dc=com] > ldap slave bind password [] > (管理者パスワードを入力) ldap tls support (1/0) [0] > SID for domain EXAMPLE_COM [(EXAMPLE_COM の SID)] > unix password encryption (CRYPT, MD5, SMD5, SSHA, SHA) [SSHA] > default user gidNumber [513] > default computer gidNumber [515] > default login shell [/bin/bash] > default skeleton directory [/etc/skel] > default domain name to append to mail adress [] >
更新される設定ファイルは次の二つです./etc/smbldap-tools/smbldap.conf /etc/smbldap-tools/smbldap_bind.conf
defaultMaxPasswordAge をコメントアウトします.#defaultMaxPasswordAge="365"
パーミッションを600に変更(パスワードが平文であるため).root@server# chmod 600 /etc/smbldap-tools/smbldap_bind.conf
- smbldap-populate による必須ユーザの登録
smbldap-populateにより,PDC運用のためのユーザおよびグループが作成されます.
root@server# smbldap-populate Populating LDAP directory for domain EXAMPLE_COM ((EXAMPLE_COM の SID)) (using builtin directory structure) entry dc=example,dc=com already exist. adding new entry: ou=Users,dc=example,dc=com adding new entry: ou=Groups,dc=example,dc=com adding new entry: ou=Computers,dc=example,dc=com adding new entry: ou=Idmap,dc=example,dc=com adding new entry: uid=root,ou=Users,dc=example,dc=com adding new entry: uid=nobody,ou=Users,dc=example,dc=com adding new entry: cn=Domain Admins,ou=Groups,dc=example,dc=com adding new entry: cn=Domain Users,ou=Groups,dc=example,dc=com adding new entry: cn=Domain Guests,ou=Groups,dc=example,dc=com adding new entry: cn=Domain Computers,ou=Groups,dc=example,dc=com adding new entry: cn=Administrators,ou=Groups,dc=example,dc=com adding new entry: cn=Account Operators,ou=Groups,dc=example,dc=com adding new entry: cn=Print Operators,ou=Groups,dc=example,dc=com adding new entry: cn=Backup Operators,ou=Groups,dc=example,dc=com adding new entry: cn=Replicators,ou=Groups,dc=example,dc=com entry sambaDomainName=EXAMPLE_COM,dc=example,dc=com already exist. Updating it... Please provide a password for the domain root: Changing UNIX and samba passwords for root New password: (root用パスワードを入力) Retype new password: (root用パスワードを入力)
- グループの登録
この登録をしなければ,Samba/LDAPサーバは Linux のグループを Windows のグループとして認識しません.ここでは,管理者グループを admin (gid=1000), ユーザグループを user (gid=1500), マシングループを computer (gid=2000) としています.
root@server# net groupmap add unixgroup=admin rid=1000 type=domain root@server# net groupmap add unixgroup=user rid=1500 type=domain root@server# net groupmap add unixgroup=computer rid=2000 type=domain
- ユーザアカウントの追加
テストユーザ smbtest を追加し,正常にアカウントが追加されていることを確認します./etc/group には追加されないことに注意して下さい.
root@server# smbldap-groupadd -g 2500 -a smbtest
/etc/passwd には追加されないことに注意して下さい.root@server# smbldap-useradd -a -m -g smbtest -c "Samba Test" -u 2500 smbtest root@server# ls -ld /home/smbtest drwxr-xr-x 2 smbtest smbtest 4096 5月 7 22:37 /home/smbtest root@server# smbldap-passwd smbtest New password: (sambatestユーザー用のパスワードを入力) Retype new password: (sambatestユーザー用のパスワードを再入力)
Linux のクライアントマシン(ホスト名は client)からLDAPサーバのデータベースを参照できるように設定します(LDAPクライアントの設定(Linux)).client 上のユーザ someone から smbtest を参照できるかチェックします.someone@client% id smbtest uid=2500(smbtest) gid=2500(smbtest) 所属グループ=2500(smbtest) someone@client% su - smbtest smbtest@client%
- ユーザアカウントの削除
テストユーザのアカウントを削除し,正常に動作していることを確認します.
root@server# smbldap-userdel -r sambatest root@server# ls -ld /home/smbtest ls: /home/smbtest: そのようなファイルやディレクトリはありません root@server# smbldap-groupdel sambatest
- 管理ユーザを Domain Admins へ登録
管理者を Domain Admins に登録すれば,Windows の管理者権限が得られます.ここでは,someadmin を登録する例を示します.
root@server# /usr/sbin/smbldap-groupmod -m someadmin "Domain Admins"
2011/06/21時点で,Windows 7 を Samba ドメインに参加させるためには,レジストリ編集を含む手続きを踏まなくてはなりません.Windows 7 の samba ドメイン参加 を参照して下さい.
梅原 大祐 / UMEHARA Daisuke umehara@kit.ac.jp Last modified: 2020/05/01 15:37