How to build Samba PDC (squeeze)
Get release image for Debian GNU/Linux
small CD にある 180MB 以下のイメージを入手。
- debian-6.0.0-i386-netinst.iso を使用
Build VMware Virtual Machine
How to create VM
Run the Virtual Machine Wizard
- Select Custom
- Select Workstation 5 as Hardware compatibility
- Do not check ESX Server
- Select Linux as guest OS
- Select Debian 5 as version
- Set sambapdc as VM's name
- Set 1 as number of CPU
- Set 256MB as available memory
- Leave NAT at Network Connection
- Leave LSI Logic at I/O controller type
- Select Create new virtual disk
- Select SCSI as type of virtual disk and leave other settings
Squeeze インストール
インストーラでの設定
インストーラで以下を指定
- 初期画面で「Install」を選択(Graphical Installではなく)
- 「Choose language」で「English」を選択
- 「Choose country」で「Japan」を選択
- 「Default locale」で「United States」を選択
- 「Keymap to use」で「American English」を選択
- 「Configure network」で以下を指定
- ホスト名「sambapdc」
- ドメイン名「sambadom.local」
- 「Set up users and passwords」で以下を指定
- 「Root password」に「samba」を指定
- 「Set up users and passwords」の「Full name for new user」で
- 「Debian installer main menu」になるまで、何度か「<Go back>」を選択
- これを行わずに普通にインストールを続行すると、無用なパッケージがイン
- ストールされるので注意。
- 「Partition disks」で以下を指定
- 「Guided - use entire disk(デフォルト)」を選択
- パーティション構成で「All files in one partition(デフォルト)」を
- 選択
- 「Finish partitioning and write changes to disk」を押す
- 「Write changes to disks?」に <Yes>を選択
- ここで「Installing the base system」画面になり、基本的なパッケージが
- インストールされる
- 「Install the GRUB boot loader on a hard disk」を選択
- Install the GRUB boot loader to the master boot record? に <yes> を
- 選択
- Installation complete で <Continue>
- ここで再起動が行われる
このほか聞かれた場合は、以下のように選択
- Install the base system を選択
- Kernel to install で「linux-image-2.6-686」を選択
- Use a network mirror で <No>
基本的な設定
- eth1 用の設定を追加(オプション)
- 仮想マシンのイメージを他で転用すると、仮想マシン起動時に「Create new identity」といったメッセージが表示される。ここで Yes を選択した場合は MAC アドレスが変更されるため、 OS から認識されるインタフェース名も eth0 ではなく eth1 や eth2 などになる。そのための設定
- /etc/network/interfaces に以下を追加(eth1の場合)
allow-hotplug eth1 iface eth1 inet dhcp
- APT コマンドの設定とパッケージの更新
- /etc/apt/sources.list の内容を以下に変更
deb http://ftp.jp.debian.org/debian etch main deb http://security.debian.org/ etch/updates main
- ディスク容量節約のため、main しか設定していないので注意。必要に応じて contrib や non-free も設定すること。
- /tmp を tmpfs にする(オプション→設定済)
- /etc/fstab に以下の設定を追加
/dev/shm /tmp tmpfs defaults 0 0
- これは、今後のインストール作業に際して、可能な限りディスク領域を消費しないためのもので、必須ではない。
- /var/cache/apt を tmpfs にする(オプション→設定済)
- /etc/fstab に以下の設定を追加
/dev/shm /var/cache/apt tmpfs defaults 0 0
- これは、今後のインストール作業に際して、可能な限りディスク領域を消費しないためのもので、必須ではない。
- 設定を行った場合は、一度再起動するか、以下のように mount コマンドで上記設定を有効にする
# mount /tmp # mount /var/cache/apt
- ftp のインストール(オプション→設定済)
- ファイルの受渡し用であり、動作上は不要
# apt-get install ftp # apt-get clean
- ssh のインストール(オプション)
# apt-get install ssh # apt-get clean
- SSH クライアントも併せてインストールされる。
- lv(ページャ)のインストール(オプション)
# apt-get install lv
- ACLおよび拡張属性関連のパッケージインストール
# apt-get install attr acl
- /etc/fstab で acl,user_xattr をマウントオプションに追加
- errors=remount-ro を defaults,acl,user_xattr,errors=remount-ro
に変更する。
- 変更後再起動するか、例えば以下のように remount オプションにより動的にマウントオプションを変更する。
mount -o remount,rw,acl,user_xattr,errors=remoun-ro /dev/sda1 /
Build Samba + LDAP environment
Installing and setting packages
Install and Configuring libnss-ldap and libpam-ldap
apt-get install libnss-ldap libpam-ldap
- Setting of libnss-ldap
- URL is ldapi:///
- DN is dc=sambadom,dc=local
- LDAP version is 3
- LDAP account for root is cn=admin,dc=sambadom,dc=local
- Password is ldap
- Settings of libpam-ldap
- Allow LDAP admin account ... is <Yes>
- Does the LDAP database require login? is <No>
- LDAP account for root is cn=admin,dc=sambadom,dc=local
- Password is ldap
- Adding LDAP into /etc/nsswitch.conf file
--- nsswitch.conf.org 2009-09-10 03:02:29.000000000 +0900 +++ nsswitch.conf 2009-09-07 22:10:09.000000000 +0900 @@ -4,9 +4,9 @@ # If you have the `glibc-doc-reference' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. -passwd: compat -group: compat +passwd: compat ldap +group: compat ldap shadow: compat hosts: files dns networks: files
Installing Samba and OpenLDAP
- installing slapd package
# apt-get install slapd ldap-utils
- Set ldap as Admin password
ldap-utils package is for management purpose, so it is not required for running, although the description is assumed it is installed.
- Installing Samba packages
# apt-get install samba winbind smbclient
- Set SAMBADOM as workgroup/domain name
smbclient package is for management and test purpose, so it is not required for running.
- Installing pam_smbpass package
# apt-get install libpam-smbpass
- Removing nscd
- Running nscd sometime makes a trouble that adding or removing an user or a group is not affected immediately.
# apt-get remove nscd
PAM configuration
Because pam-auth-update command automatically sets PAM related-files, basically we do not need to edit them manually.
But we have to set these settings manually:
- /etc/pam.d/common-password
- Comment out pam_winbind.so line.
- /etc/pam.d/common-session
- Add mkhomedir option in pam_winbind.so line.
Installing crackcheck command
- Installing cracklib package
- apt-get install libcrack2
- used by crackcheck command
Run on the box where development packages are installed.
# apt-get install cracklib2-dev
# apt-get install samba-doc # cd /usr/share/doc/samba-doc/examples/auth/crackcheck # make # strip crackcheck
Copy crackcheck binary to /usr/local/sbin/crackcheck on sambapdc
Extract mgrshare script (included in [http://wiki.samba.gr.jp/mediawiki/images/1/10/Sambapdc4.tar.gz sambapdc4.tar.gz] ) and install:
# mv mgrshare /usr/local/sbin/mgrshare # chmod +x /usr/local/sbin/mgrshare
Installing smbchsh
Extract smbchsh script (included in [http://wiki.samba.gr.jp/mediawiki/images/1/10/Sambapdc4.tar.gz sambapdc4.tar.gz] ) and install to /usr/local/bin/smbchsh.
Here is the content of smbchsh:
#!/bin/sh SHELL=$1 echo "dn: uid=${USER},ou=users,dc=samba,dc=local changetype: modify replace: loginShell loginShell: $1 " | ldapmodify -x -D "uid=${USER},ou=users,dc=samba,dc=local" -W
Installing remove-old-files-in-recycle-bin
Extract remove-old-files-in-recycle-bin script (included in [http://wiki.samba.gr.jp/mediawiki/images/1/10/Sambapdc4.tar.gz sambapdc4.tar.gz] ) and install as /usr/local/sbin/remove-old-files-in-recycle-bin:
#!/bin/sh trashdir=.recycle rootdir=/var/lib/samba/shares olddays=14 cd ${rootdir} for targetdir in *; do if [ -d ${targetdir}/${trashdir} ]; then cd ${targetdir}/${trashdir} find . -atime +${olddays} -exec rm {} \; fi done
Creating home directory
# mkdir /home/SAMBADOM
Creating smbusers file
Extract smbusers file (included in [http://wiki.samba.gr.jp/mediawiki/images/1/10/Sambapdc4.tar.gz Sambapdc4.tar.gz] ) and install as /etc/samba/smbusers
Setting Samba + LDAP environment
Setting LDAP
Remember that LDAP settings are stored in LDAP after Squeeze
- Installing schema file for Samba
# apt-get install samba-doc # apt-get clean
# zcat /usr/share/doc/samba-doc/examples/LDAP/samba.schema.gz > /etc/ldap/schema/samba.schema
# apt-get remove samba-doc # apt-get clean
- samba-doc package is removed after extracting schema file
- Generating LDIF file for Samba schema
# cd /tmp # ln -s /etc/ldap/schema . # mkdir dummy_slapd.d
- Creating /tmp/dummy_slapd.conf file as below:
include schema/core.schema include schema/cosine.schema include schema/inetorgperson.schema include schema/nis.schema include schema/samba.schema
# slaptest -f dummy_slapd.conf -F dummy_slapd.d config file testing succeeded
- Modifying LDIF file
Rename cn={4}samba.ldif under dummy_slapd.d/cn=config/cn=schema to samba.ldif
and modify as below:
- The top 3 lines before:
dn: cn={4}samba objectClass: olcSchemaConfig cn: {4}samba
- The top 3 lines after:
dn: cn=samba,cn=schema,cn=config objectClass: olcSchemaConfig cn: samba
- The last 7 lines before:
structuralObjectClass: olcSchemaConfig entryUUID: a671adca-3aa0-1030-8ae6-516ef773ec5f creatorsName: cn=config createTimestamp: 20110704154721Z entryCSN: 20110704154721.872107Z#000000#000#000000 modifiersName: cn=config modifyTimestamp: 20110704154721Z
- The last 7 line after:
(Removed)
- Register samba.ldif
# ldapadd -Y EXTERNAL -H ldapi:/// -f samba.ldif adding new entry "cn=samba,cn=schema,cn=config"
- Initial settings
- Create sambadom.ldif as below:
dn: olcDatabase={1}hdb,cn=config changetype:modify add: olcDbIndex olcDbIndex: uidNumber,gidNumber,uid,sambaSID,cn,memberuid eq - add: olcAccess olcAccess: to attrs=loginShell by dn="cn=admin,dc=samba,dc=local" write by self write by * read olcAccess: to attrs=sambaNTPassword,sambaLMPassword,sambaPwdLastSet,sambaPwdMustChange by dn="cn=admin,dc=samba,dc=local" write by self write by * none
# ldapadd -Y EXTERNAL -H ldapi:/// -f sambadom.ldif adding new entry "olcDatabase={1}hdb,cn=config"
Create initial schema
- Create sambadom.local.ldif file as below:
dn: ou=users,dc=sambadom,dc=local objectClass: top objectClass: organizationalUnit ou: users dn: ou=groups,dc=sambadom,dc=local objectClass: top objectClass: organizationalUnit ou: groups dn: ou=idmap,dc=sambadom,dc=local objectClass: top objectClass: organizationalUnit ou: idmap dn: ou=computers,dc=sambadom,dc=local objectClass: top objectClass: organizationalUnit ou: computers
- Register sambadom.local.ldif with ldapadd :
# cat sambadom.local.ldif | ldapadd -D cn=admin,dc=sambadom,dc=local -W -x -H ldapi:/// Enter LDAP Password: adding new entry "ou=users,dc=samba,dc=local" adding new entry "ou=groups,dc=samba,dc=local" ...
Setting Samba
- Stopping Samba
# /etc/init.d/samba stop # /etc/init.d/winbind stop
- Installing smb.conf
Create smb.conf as /etc/samba/smb.conf (included in sambapdc4.tar.gz)
# mv /etc/samba/smb.conf /etc/samba/smb.conf.org # mv smb.conf /etc/samba/smb.conf
- Installing smbusers file
Create smbusers as /etc/samba/smbusers
- Store LDAP password
# smbpasswd -w ldap Setting stored password for "cn=admin,dc=sambadom,dc=local" in secrets.tdb
- Store initial settings into LDAP
Start winbindd (only) before running 'net sam provision'
# /etc/init.d/winbind start Starting the Winbind daemon: winbind. # net sam provision Checking for Domain Users group. Adding the Domain Users group. Checking for Domain Admins group. Adding the Domain Admins group. Check for Administrator account. Adding the Administrator user. Checking for Guest user. Adding the Guest user. Checking Guest's group. Adding the Domain Guests group.
- Initial settings for Administrator user
- Setting his password 'samba'
# smbpasswd Administrator New SMB password: <== samba Retype new SMB password: <== samba
- Starting Samba
Setting automated home directory creation
- Create a file as /usr/local/sbin/createhomedir and chmod +rx :
- This setting is needed because automated home directory creation via PAM cannot work with Samba.
#!/bin/bash homedir=/home/$1/$2 if [ ! -d $homedir ]; then mkdir $homedir chmod 700 $homedir chown $2:domusers $homedir fi exit 0
Setting syslog
- Creating a file as /etc/rsyslog.d/samba.conf :
local1.* -/var/log/samba/log.audit
- And
# touch /var/log/samba/log.audit # /etc/init.d/rsyslog restart
- Creating a file as /etc/logrotate.d/samba-syslog :
/var/log/samba/log.audit { rotate 4 weekly missingok notifempty compress delaycompress sharedscripts postrotate invoke-rc.d rsyslog reload > /dev/null endscript }
# mkdir /var/lib/samba/shares # cd /var/lib/samba/shares
- 'NETLOGON' share
# mkdir /var/lib/samba/shares/netlogon
# mkdir /var/lib/samba/shares/printers # chmod 775 domadmins # chgrp domadmins printers
- 'profiles' share
# mkdir /var/lib/samba/shares/profiles # chmod 1777 /var/lib/samba/shares/profiles
- 'shared' share
- shares where users who belong to Domain Users group can read and write
# mkdir /var/lib/samba/shares/shared # chgrp domusers shared # chmod g+ws shared
- 'aclshare1' share
- Create aclshare1ro and aclshare1rw group and confirm their GID before creating 'aclshare1'
# net sam createlocalgroup aclshare1ro Created local group aclshare1ro with RID 1001 # net sam createlocalgroup aclshare1rw Created local group aclshare1rw with RID 1002
# net groupmap list ntgroup=aclshare1ro aclshare1ro (S-1-5-21-3643489711-3443204727-2039806625-1001) -> 10011 # net groupmap list ntgroup=aclshare1rw aclshare1rw (S-1-5-21-3643489711-3443204727-2039806625-1002) -> 10012
# mkdir /var/lib/samba/shared/aclshare1 # chown root:root aclshare1 # chmod 770 aclshare1 # setfacl -m group:10011:r-x aclshare1 # setfacl -m group:10012:rwx aclshare1 # setfacl -d -m group:10011:r-x aclshare1 # setfacl -d -m group:10012:rwx aclshare1
- 'aclshare2' share
- Create aclshare2ro and aclshare2rw group and confirm their GID before creating 'aclshare2'
# net sam createlocalgroup aclshare2ro Created local group aclshare1ro with RID 1003 # net sam createlocalgroup aclshare2rw Created local group aclshare1rw with RID 1004
# net groupmap list ntgroup=aclshare1ro aclshare1ro (S-1-5-21-3643489711-3443204727-2039806625-1003) -> 10013 # net groupmap list ntgroup=aclshare1rw aclshare1rw (S-1-5-21-3643489711-3443204727-2039806625-1004) -> 10014
# mkdir /var/lib/samba/shared/aclshare1 # chown root:root aclshare1 # chmod 770 aclshare1 # setfacl -m group:10014:rwx aclshare2 # setfacl -m group:10013:r-x aclshare2 # setfacl -d -m group:10014:rwx aclshare2 # setfacl -d -m group:10013:r-x aclshare2
- 'share_test' share
# mkdir /var/lib/samba/shares/share_test # chmod 1777 share_test
# mkdir share_test/hide_unreadable # cd share_test/hide_unreadable # touch normal.txt # touch secure.txt # chmod 600 secure.txt
# mkdir share_test/veto_files # cd share_test/veto_files # touch dummy.exe # mkdir GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
- Installing var-check script
- works with "root preexec" line on share_test share and shows all value of Samba variables. Installing as /usr/local/sbin/var-check:
#!/bin/sh VARLIST='%U %G %h %L %m %M %R %d %a %I %i %T %D %w %v %V %S %P %u %g %H %N %p e1 e2' rm /tmp/var.txt for var in $VARLIST; do echo "$var : $1" >> /tmp/var.txt shift done
Creating users
- Creating ldap01, ldap02 and ldap03 user
- ldap01 and ldap02 user belong to aclshare1rw and aclshare2rw group
- ldap03 user belongs to aclshare1ro and aclshare2ro group
- Their home directory is set as \\sambapdc\username, mounted to H:
- Their username is set as "LDAP User nn"
- Their password is set not to expired.
- For ldap01 user
# smbpasswd -a ldap01 # pdbedit -c "[X]" -f "LDAP01 user" -h '\\sambapdc\ldap01' -D h: ldap01
# net sam addmem aclshare1rw ldap01 Added SAMBADOM\ldap01 to SAMBADOM\aclshare1rw # net sam addmem aclshare2rw ldap01 Added SAMBADOM\ldap01 to SAMBADOM\aclshare2rw
Installing SWAT (Option)
- Installing SWAT
# apt-get install swat
- Setting below to /etc/hosts.allow file
- Resticted access into local subnet.
ALL: LOCAL
Last of all
- Initialization WINS database
Remove wins.dat and wins.tdb under /var/lib/samba
- Removing VMware log files