ติดตั้ง และ คอนฟิก Samba Domain Controller

ติดตั้งและคอนฟิก Samba Server

1. ติดตั้ง Samba ด้วยคำสั่ง apt-get install ดังนี้
apt-get install samba samba-common samba-doc libcupsys2-gnutls10 libkrb53 winbind smbclient

2. แก้ไขไฟล์ /etc/samba/smb.conf ดังนี้

[global]
workgroup = MYWORKGROUP
netbios name = SERVER1
server string = %h server (Samba, Ubuntu)
passdb backend = tdbsam
security = user
username map = /etc/samba/smbusers
name resolve order = wins bcast hosts
domain logons = yes
preferred master = yes
wins support = yes

# Set CUPS for printing
printcap name = CUPS
printing = CUPS

# Default logon
logon drive = H:
logon script = scripts/logon.bat
logon path = \\server1\profile\%U

# Useradd scripts
add user script = /usr/sbin/useradd -m %u
delete user script = /usr/sbin/userdel -r %u
add group script = /usr/sbin/groupadd %g
delete group script = /usr/sbin/groupdel %g
add user to group script = /usr/sbin/usermod -G %g %u
add machine script = /usr/sbin/useradd -s /bin/false/ -d /var/lib/nobody %u
idmap uid = 15000-20000
idmap gid = 15000-20000

# sync smb passwords woth linux passwords
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n .
passwd chat debug = yes
unix password sync = yes

# set the loglevel
log level = 3

[homes]
comment = Home
valid users = %S
read only = no
browsable = no

[printers]
comment = All Printers
path = /var/spool/samba
printable = yes
guest ok = yes
browsable = no

[netlogon]
comment = Network Logon Service
path = /home/samba/netlogon
admin users = Administrator
valid users = %U
read only = no

[profile]
comment = User profiles
path = /home/samba/profiles
valid users = %U
create mode = 0600
directory mode = 0700
writable = yes
browsable = no
หมายเหตุ : ค่า "netbios name" ในไฟล์ smb.conf ต้องเหมือนกับ hostname ของ Server
workgroup = MYWORKGROUP ให้ระบุ Windows domain ที่ใช้ใน Windows workstation
logon drive = H: เป็น drive letter ภายใต้การ share ของ SAMBA ซึ่งจะปรากฎใน Windows Explorer

With logon script = scripts/logon.bat สามารถระบุ Windows batch script ที่จะถูก execute ทันทีเมื่อ Windows workstation ทำการ login ถ้าไม่มี script ก็สามารถใช้ comment บรรทัดนี้ได้
3. ทำการสร้างไดเร็คทอรี่สำหรับ domain logon และ profile ดังนี้

mkdir /home/samba
mkdir /home/samba/netlogon
mkdir /home/samba/profiles
mkdir /var/spool/samba
chmod 777 /var/spool/samba/
chown -R root:users /home/samba/
chmod -R 771 /home/samba/

4 ทำการ restart samba ด้วยคำสั่ง

/etc/init.d/samba restart

5. ทำการแก้ไขไฟล์ /etc/nsswitch.conf โดยเปลี่ยนบรรทัด :

hosts: files dns ไปเป็น :

hosts: files wins dns

6. ทำการเพิ่ม computers ใน workgroup ทั้งหมดเข้าไปในไฟล์ /etc/hosts ของ server เช่น

192.168.0.100 server1
192.168.0.110 workstation1
192.168.0.111 workstation2
192.168.0.112 workstation3
192.168.0.113 workstation4

7. เพิ่ม root user เข้าไปยัง SAMBA password database โดย root user (alias: Administrator) นี้จะเป็น domain administrator ของเรา ซึ่ง account นี้มีความจำเป็นสำหรับการเพิ่ม computers ใหม่เข้าไปยัง SAMBA domain

smbpasswd -a root

สร้างไฟล์ /etc/samba/smbusers และเพิ่มข้อความหนึ่งบรรทัดเข้าไปในไฟล์โดยการ execute คำสั่ง :

echo "root = Administrator" > /etc/samba/smbusers

8. ทดสอบการ setup ว่าถูกต้องหรือไม่ ด้วยคำสั่ง :

smbclient -L localhost -U%

ซึ่งผลที่ได้ควรจะเป็นดังนี้ :
Domain=[MYWORKGROUP] OS=[Unix] Server=[Samba 3.0.14a-Ubuntu]

Sharename Type Comment
--------- ---- -------
netlogon Disk Network Logon Service
print$ Disk Printer Drivers
IPC$ IPC IPC Service (server1 server (Samba, Ubuntu))
ADMIN$ IPC IPC Service (server1 server (Samba, Ubuntu))
Domain=[MYWORKGROUP] OS=[Unix] Server=[Samba 3.0.14a-Ubuntu]

Server Comment
--------- -------
SERVER1 server1 server (Samba, Ubuntu)

Workgroup Master
--------- -------
MDKGROUP IPRG
MYWORKGROUP SERVER1

9.0ทำการเซ็ตอัพ default domain groups สำหรับ Windows ด้วยคำสั่งต่อไปนี้ :

net groupmap modify ntgroup="Domain Admins" unixgroup=root
net groupmap modify ntgroup="Domain Users" unixgroup=users
net groupmap modify ntgroup="Domain Guests" unixgroup=nogroup

เพิ่ม Users เข้ากับ SAMBA Domain ของเรา

10. ทำการเพิ่ม user เข้าไปยัง SAMBA domain ของเรา ซึ่งหมายถึง user ที่ต้องการจะเชื่อมต่อเข้ากับกับ SAMBA domain server เช่นถ้า user ชื่อ tom ก็สามารถเพิ่มโดยใช้คำสั่งดังนี้

เพิ่ม linux user ของ tom :

useradd tom -m -G users

เพิ่ม linux server ของ tom เข้ากับ SAMBA password database :

smbpasswd -a tom
เพิ่มการ share

11.ทำการเพิ่มพื้นที่ของการ share ซึ่งในที่นี้เราจะสร้างพื้นที่ที่จะ share ให้กับ user ทุกคน โดยใช้คำสั่งดังนี้ :

mkdir -p /home/shares/allusers
chown -R root:users /home/shares/allusers/
chmod -R ug+rwx,o+rx-w /home/shares/allusers/

และที่ส่วนท้ายของไฟล์ /etc/samba/smb.conf ให้เพิ่มบรรทัดข้อความต่อไปนี้ :

[allusers]
comment = All Users
path = /home/shares/allusers
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
writable = yes

12. และถ้าไม่ต้องการติดตั้งโปรแกรมในส่วนของ print server ก็ให้ทำการ restart samba ดังนี้ :

/etc/init.d/samba restart

จากนั้นก็ให้ทดลองใช้งานดู

ติดตั้ง CUPS

13. ถ้าต้องการให้ SAMBA Server ของคุณเป็น Print Server ด้วย ก็จะต้องมีการติดตั้งและคอนฟิก CUPS
1. ติดตั้งโปรแกรมโดยใช้คำสั่งหนึ่งบรรทัดยาว ๆ ดังนี้ :

apt-get install cupsys cupsys-client cupsys-driver-gimpprint cupsys-driver-gimpprint-data defoma fontconfig foomatic-db foomatic-filters libcupsimage2 libexpat1 libfontconfig1 libfreetype6 libgimpprint1 libjpeg62 libpaper1 libpng12-0 libpoppler0c2 libslp1 libtiff4 patch perl perl-modules ttf-bitstream-vera ucf

ในกรณีที่ติดตั้งไม่ได้ก็อาจจะแก้ได้ด้วยการใช้คำสั่ง :

apt-get update

2. เพื่อให้สามารถ Access ผ่าน Web Interface จากเครื่องที่เป็น Workstation ได้ ก็ให้ทำการเปลี่ยนแปลงให้ CUPS มีการเฝ้าคอย (listen) ที่ IP ของ Server ด้วยการแก้ไขส่วนของ Network Options ของไฟล์ /etc/cups/cupsd.conf ดังนี้ :

Listen 127.0.0.1:631
Listen 192.168.0.100:631

3. ให้เซ็ต AuthGroupName เป็น shadow ในส่วนของ Security Options ดังนี้ :

AuthGroupName shadow

4. เพื่ออนุญาตให้ access ได้เฉพาะจาก my admin workstation (IP : 192.168.0.70) ให้เพิ่ม Allow From 192.168.0.70 ใน security options และเซ็ต AuthClass เป็น Group ดังนี้ :


#
# You definitely will want to limit access to the administration functions.
# The default configuration requires a local connection from a user who
# is a member of the system group to do any admin tasks. You can change
# the group name using the SystemGroup directive.
#

AuthType Basic
AuthClass Group

## Restrict access to local domain
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
Allow From 192.168.0.70

#Encryption Required
n>

5. เพิ่ม cups users เข้าไปยังกลุ่ม shadow ดังนี้ :

adduser cupsys shadow

6. ทำการ restart cupsys ดังนี้ :

/etc/init.d/cupsys restart


7. ตอนนี้ cups webinterface สามารถจะ access ได้แล้วผ่าน browser โดยใช้ยูสเซอร์ root และรหัสผ่านของ root ด้วยการเรียก :

http://192.168.0.100:631/