Samba 4.19.4 - Stable Release

Samba 4.18/4.19

คู่มือ advance สำหรับ Linux Sysadmin

Security Hardening, Active Directory Integration, High Availability, Performance Tuning และ Troubleshooting แบบละเอียด

Security Hardening
AD Integration
High Availability
Performance Tuning

เนื้อหาในบทความนี้

1 บทนำ: Samba คืออะไร และทำไมถึงจำเป็นในยุคปัจจุบัน

Samba คืออะไร?

Samba (Server Message Block) คือซอฟต์แวร์แบบโอเพนซอร์สที่ทำหน้าที่เป็นตัวกลางในการเชื่อมต่อระหว่างระบบปฏิบัติการ โดยเฉพาะการแชร์ไฟล์และปริ้นเตอร์ระหว่างระบบปฏิบัติการต่างกัน (Windows, Linux, macOS)

Samba ถูกพัฒนาขึ้นในปี 1992 โดย Andrew Tridgell เพื่อให้ Linux สามารถเข้าถึงไฟล์ที่แชร์จากเครื่อง Windows ได้ ปัจจุบัน Samba ได้พัฒนาไปมากและสามารถทำงานได้ทั้งเป็น File Server และ Active Directory Domain Controller

ประวัติการพัฒนา Samba

1992 Andrew Tridgell ผู้ก่อตั้ง Samba
2017 Samba 4.6 - รองรับ Active Directory Domain Controller
2023 Samba 4.18 - ปฏิรูป Lock Subsystem (เร็วขึ้น 3 เท่า)
2024-2026 Samba 4.19 - 4.23 - Current Stable Series

ใช้งานใน Corporate Environment

Samba ถูกใช้งานอย่างกว้างขวางในองค์กรขนาดใหญ่สำหรับการแชร์ไฟล์ภายในเครือข่าย โดยเฉพาะในสภาพแวดล้อมที่มีทั้ง Windows และ Linux และสามารถผสานรวมเข้ากับ Active Directory ได้อย่างสมบูรณ์

  • interoperability: เชื่อมต่อระหว่าง Windows ↔ Linux ได้โดยไม่มีปัญหา
  • Cost effective: ไม่ต้องจ่ายค่าลิสเซนส์เหมือน File Server บน Windows
  • Flexible: ปรับแต่งได้ตามความต้องการและรองรับความต้องการเฉพาะ

ตัวอย่างการใช้งานในประเทศไทย

โรงพยาบาล

แชร์เอกสารทางการแพทย์ระหว่างแผนกต่าง ๆ ระบบบันทึกผลการตรวจรักษา

มหาวิทยาลัย

แชร์ไฟล์ของแต่ละแผนก จัดการบัญชีนักศึกษาและอาจารย์ผ่าน AD Integration

โรงงานอุตสาหกรรม

ระบบCollect ข้อมูลการผลิต แชร์รายงานระหว่างเครื่องผลิตและระบบรายงาน

ทำไมต้องใช้ Samba?

คำถามที่สำคัญ: แล้วทำไมไม่ใช้ NFS หรือ Cloud Storage เปล่า ๆ?

Samba vs NFS: Samba รองรับ SMB/CIFS protocol ที่ Windows เข้าใจได้โดยตรง ขณะที่ NFS ต้องติดตั้ง NFS client บน Windows

Samba vs Cloud Storage: สำหรับข้อมูลภายในองค์กรที่ต้องการความเร็วสูงและควบคุมได้เต็มที่ Samba ยังคงเป็นทางเลือกที่ดีที่สุด

2 โครงสร้างระบบ: Architecture & How It Works

Samba ทำงานบนProtocols คือ Server Message Block (SMB) และ Common Internet File System (CIFS) ซึ่งเป็นมาตรฐานสำหรับการแชร์ไฟล์และปริ้นเตอร์ในเครือข่าย

Architecture Diagram: Client-Server Model

Clients Windows Linux macOS SMB/CIFS Samba Server smbd File Sharing nmbd NetBIOS winbind Authentication Unix FS Backend Storage Disk/RAID SMB Protocol Stack Legend: Client Process Samba Process SMB/CIFS Flow

Samba Processes

smbd

Function: SMB Server Daemon - รับผิดชอบการแชร์ไฟล์และปริ้นเตอร์

Ports: 445 (TCP), 139 (NetBIOS)

nmbd

Function: NetBIOS Name Service - จัดการการค้นหาชื่อเครื่องในเครือข่าย

Ports: 137/UDP (Name Service), 138/UDP (Datagram)

winbind

Function: Windows User/Group Mapping - ผสานรวม user/group กับ Active Directory

Integration: /etc/passwd, /etc/group

SMB Protocol Versions

SMBv1 (1984)

Deprecated INSECURE

Version แรกของ SMB, ไม่มี encryption, vulnerable to attacks (EternalBlue)

SMBv2 (2006)

Supported

Performance improvements, larger read/write, better caching

SMBv3 (2012)

Recommended

Encryption, continuous availability, multichannel, compression

SMB3.1.1 (2015)

Latest

AES-128 GCM encryption, PKI certificate validation, pre-authentication integrity

3 สิ่งที่ต้องเตรียม: Prerequisites

ก่อนที่จะเริ่มติดตั้งและตั้งค่า Samba อย่างละเอียด คุณจำเป็นต้องเตรียมสิ่งต่าง ๆ เหล่านี้ไว้ก่อน

Hardware Requirements

Minimum
  • CPU: Dual-core (2 GHz+)
  • RAM: 4 GB
  • Storage: 50 GB
  • Network: 1 Gbps
สำหรับทดสอบ/พัฒนาเท่านั้น
Recommended
  • CPU: 8+ cores (3 GHz+)
  • RAM: 16 GB+
  • Storage: SSD, 100 GB+
  • Network: 1-10 Gbps
สำหรับ Production Environment
High Throughput
  • CPU: 16+ cores (3.5 GHz+)
  • RAM: 32 GB+
  • Storage: NVMe SSD, RAID 10
  • Network: 10 Gbps+ with bond
สำหรับLarge-scale Deployment

Software Requirements

Operating System

Ubuntu Server Recommended
22.04 LTS / 24.04 LTS
Debian
11 / 12

Samba Version

Minimum: Samba 4.18 (Security fixes only)

Recommended: Samba 4.19 - 4.23 (Current Stable)

Network Requirements

Mandatory Network Configuration

Static IP Address

Network ต้องมี IP คงที่ (ไม่ใช่ DHCP)

DNS Resolution

Forward และ Reverse DNS ต้อง working

NTP Synchronization

Time sync ต้อง accurate (Kerberos ต้องการ)

Firewall Rules

Allow ports: 445, 139, 137/UDP, 138/UDP

Pre-flight Checklist

Before Installation - Run These Commands

# 1. Check hostname (should be FQDN)
$ hostname -f
# 2. Check network configuration
$ ip addr show
# 3. Check DNS resolution
$ cat /etc/resolv.conf
# 4. Check time synchronization
$ timedatectl status
# 5. Update system
$ sudo apt update && sudo apt upgrade -y

Tip: สำหรับการติดตั้งแบบ Advance ที่ต้อง compile จาก source ควรเตรียม space มากกว่านี้หน่อย (50+ GB)

5 ขั้นตอนที่ 2: โครงสร้าง smb.conf - Configuration Explained

ไฟล์ configuration หลักของ Samba คือ /etc/samba/smb.conf ไฟล์นี้จะกำหนดค่าทั้ง global และ share settings

# Main configuration sections
[global]
# Global settings apply to the entire Samba server
# Workgroup, security, logging, etc.
[shares]
# Individual share definitions
# Path, permissions, users, etc.
[printers]
# Printer share definitions (optional)
# Only needed if printer sharing is required

Global Section Settings

workgroup
ชื่อ Workgroup หรือ Domain name
Example: WORKGROUP หรือ EXAMPLE.COM
server string
คำอธิบายของไฟล์เซิร์ฟเวอร์
Example: Samba File Server 2026
security
ระดับความปลอดภัย
User, ADS, Server
map to guest
จัดการการเข้าถึงแบบ guest
bad user, never, always

Share Section Settings

path
Directory path ที่จะแชร์
Example: /srv/samba/shared
browsable
แสดงใน list ของ network
yes หรือ no
writable
อนุญาตให้เขียนไฟล์
yes หรือ no
valid users
ผู้ใช้ที่อนุญาตให้เข้าถึง
Example: @users, @domain-admins

ตัวอย่าง smb.conf แบบสมบูรณ์

[global] # workgroup - SMB/CIFS workgroup name # server string - description of server # security - security mode (user, ads) # map to guest - how to handle guest access # dns proxy - try to resolve names via DNS # log file - location of log files # max log size - maximum size of log files # obey pam restrictions - use PAM for authentication # unix password sync - sync unix password # pam password change - use PAM for password change # invalid users - users that cannot login # hosts allow - allowed hosts # hosts deny - denied hosts
Tip: หลังจากแก้ไข smb.conf ให้รัน testparm เพื่อตรวจสอบ syntax ก่อน restart service

6 ขั้นตอนที่ 3: Security Hardening Guide

การรักษาความปลอดภัยเป็นสิ่งสำคัญที่สุดเมื่อตั้งค่า Samba Server บทความนี้จะพาคุณผ่านการ hardening แบบ step-by-step

คำเตือนสำคัญ

Samba ถูกใช้งานในหลายองค์กรสำหรับแชร์ข้อมูลที่สำคัญ การตั้งค่าที่ไม่ปลอดภัยอาจทำให้ข้อมูลรั่วไหลหรือถูกโจมตีได้ อย่าลืมทำ security hardening เสมอ!

1 Disable SMBv1 - สำคัญที่สุด!

SMBv1 เป็น protocol ที่เก่าแก่และมีช่องโหว่หลายช่อง (EternalBlue เป็นตัวอย่าง) ต้อง disable เด็ดขาด!

# Add to smb.conf [global] section
server min protocol = SMB2
server max protocol = SMB3_11
testparm -v | grep 'server min protocol'

2 Enable SMB Signing - Required for AD

SMB signing ป้องกันการโจมตีแบบ man-in-the-middle โดยการ signing ทุก packet ด้วย cryptographic signature

# Add to smb.conf [global] section
server signing = required
smb sign = required

3 Force Encryption - Protect data in transit

การ encrypt data ระหว่าง client กับ server เป็นสิ่งจำเป็น

# For shares that need encryption
encryption = required

Note: Encryption ส่งผลต่อ performance ประมาณ 5-10%

4 Restrict Anonymous Access - Security best practice

อย่าอนุญาตให้ guest หรือ anonymous เข้าถึงข้อมูลของคุณ

# Add to smb.conf [global] section
map to guest = never
null passwords = no

5 Firewall Configuration

ใช้ firewall เพื่อจำกัดการเข้าถึงแค่ IP ที่จำเป็นเท่านั้น

sudo ufw allow from 192.168.1.0/24 to any port 445
sudo ufw allow from 192.168.1.0/24 to any port 139
อย่าเปิด port 445 ให้ internet ถ้าไม่จำเป็น!

6 Enable Logging & Monitoring

Logging เป็นสิ่งสำคัญสำหรับการ audit และ troubleshooting

# Logging configuration
log file = /var/log/samba/log.%m
log level = 3
max log size = 1024

7 Disk Quotas - Prevent resource exhaustion

ตั้งค่า quota เพื่อป้องกันไม่ให้ user เก็บไฟล์เกินขอบเขต

sudo setquota -u username 10000000 10000000 1000 1000 /data
repquota -a

ตัวอย่างนี้ตั้ง quota 10GB per user

7 ขั้นตอนที่ 4: Active Directory Integration

การผสานรวม Samba กับ Active Directory ทำให้สามารถใช้บัญชี AD ในการเข้าถึงไฟล์แชร์ และจัดการผู้ใช้แบบรวมศูนย์ได้

ข้อดีของการใช้ AD Integration

  • Centralized management: จัดการผู้ใช้จาก AD ที่เดียว
  • Single sign-on: เข้าถึงไฟล์โดยไม่ต้อง login อีกครั้ง
  • Group-based permissions: กำหนดสิทธิ์ตาม AD group
  • POLICY enforcement: ใช้ GPO ควบคุมการใช้งาน

1 Prerequisites สำหรับ AD Integration

Network
  • Hostname ต้องเป็น FQDN (server.example.com)
  • DNS ต้องชี้ไปที่ Domain Controller
  • Time sync ต้อง accurate (NTP)
Packages
sudo apt install realmd adcli sssd sssd-tools libpam-sss libnss-sss -y

2 ตั้งค่า NTP synchronized

Kubernetes และ Kerberos ต้องการ time sync ที่แม่นยำมาก

sudo timedatectl set-ntp true && sudo timedatectl set-timezone Asia/Bangkok
sudo systemctl restart systemd-timesyncd
timedatectl status

3 Discover Domain

ตรวจสอบว่าสามารถ discover domain ได้หรือไม่

sudo realm discover example.com

Replace example.com dengan domain ของคุณ

Expected output: Domain: example.com, Server: dc.example.com

4 Join Domain

Join เครื่องนี้เข้ากับ domain AD

sudo realm join -U administrator@example.com example.com

ต้องกรอกรหัสผ่านของ AD user ที่มีสิทธิ์ join domain

5 Configure NSS & PAM

ตั้งค่าให้ระบบใช้ SSSD สำหรับ user/group lookup

sudo pam-auth-update

ในหน้าต่างที่ปรากฏ ให้เลือก: Create home directory on login

6 Configure Samba for AD

แก้ไข smb.conf ให้ใช้ ADS security mode

# แทนที่ส่วน [global] ด้วย:
[global]
workgroup = EXAMPLE
realm = EXAMPLE.COM
security = ADS
map to guest = Never
winbind use default domain = Yes
winbind enum users = Yes
winbind enum groups = Yes
idmap config * : backend = tdb
idmap config * : range = 100000-199999
idmap config EXAMPLE : backend = rid
idmap config EXAMPLE : range = 1000000-1999999
sudo systemctl restart winbind smbd

7 Test AD Integration

ตรวจสอบว่าสามารถดึง user และ group จาก AD ได้หรือไม่

getent passwd administrator@example.com
getent group "domain users"
wbinfo -u

หากได้ output แสดงว่า integration สำเร็จ!

8 ขั้นตอนที่ 5: Performance Tuning

การ optimize Samba ให้ทำงานได้เร็วขึ้นสามารถทำได้หลายวิธี ทั้งจาก configuration และ system-level tuning

1 SMB Protocol Version

ใช้ SMB version ล่าสุดที่ client รองรับเพื่อประสิทธิภาพสูงสุด

server min protocol = SMB2
server max protocol = SMB3_11
SMB3.1.1 มี encryption และ compression

2 Large Read/Write Size

ปรับขนาด buffer สำหรับ read/write ด้วย

rsize = 1048576
wsize = 1048576
aio read size = 16384
aio write size = 16384

3 Use Sendfile for Better Performance

sendfile ช่วยให้ kernel ส่งข้อมูลโดยตรงจาก disk ไปยัง network

use sendfile = yes
write cache size = 2097152

4 Large Directory Handling

การตั้งค่าที่เหมาะสมสำหรับ directory ที่มีไฟล์นับพัน

kernel change notify = yes
oplocks = yes
level2 oplocks = yes
open files world readable = yes

คำแนะนำ: หากมีไฟล์มากกว่า 100K ให้พิจารณา use case-sensitive = no หรือใช้ lowercase directory names

5 Socket Buffer Tuning

เพิ่มขนาด buffer สำหรับ socket communication

# Add to /etc/sysctl.conf
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.rmem_default = 262144
net.core.wmem_default = 262144
sudo sysctl -p

6 File System Optimization

File system settings มีผลต่อ performance ของ Samba

ext4/xfs mount options
defaults,noatime,nodiratime
Recommended

xfs มักจะเร็วกว่า ext4 สำหรับ large files

7 Performance Testing

วัดผลก่อนและหลังการ tune เพื่อดูความแตกต่าง

sudo apt install iozone3 -y
iozone -a -n 5 -g 1G -I -r 64k -s 1g > /tmp/iozone_before.log

เปรียบเทียบ output ก่อนและหลังการ tune

9 ขั้นตอนที่ 6: High Availability & Clustering

สำหรับองค์กรที่ต้องการ file server ที่ไม่มีจุดล้มเหลวเดียว (SPOF) การตั้งค่า High Availability เป็นสิ่งจำเป็น

วิธี High Availability ที่นิยม

1
DRBD + Pacemaker (Block-level)

ซิงค์ข้อมูลที่ block level ระหว่าง two nodes

2
CTDB (Distributed TDB)

สำหรับ cluster ที่ต้องการ active-active

3
CephFS + Samba

Distributed filesystem ที่ scale ได้ดี

1 Architecture Overview

Active/Passive Configuration
  • Node 1 (Active): Samba service running, serving clients
  • Node 2 (Passive): Monitoring active node, ready to take over
  • DRBD: Real-time data replication between nodes
  • Pacemaker: Cluster manager, handles failover

2 Install Cluster Packages

ทั้งสอง nodes ต้องติดตั้ง packages เหล่านี้

sudo apt install pacemaker corosync drbd-utils resource-agents -y

ขั้นตอนต่อไป: Configure DRBD สำหรับ data replication

3 Configure DRBD

# /etc/drbd.d/r0.res - Configure on both nodes
resource r0 {
protocol C;
inet6 auto;
on node1 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.1.10:7788;
meta-disk internal;
}
on node2 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.1.11:7788;
meta-disk internal;
}
}
sudo drbdadm create-md r0 && sudo systemctl start drbd

4 Configure Corosync

# /etc/corosync/corosync.conf
compatibility: whitetank
totem {
version: 2
secauth: off
interface {
ringnumber: 0
bindnetaddr: 192.168.1.0
mcastport: 5405
}
}
sudo systemctl enable corosync pacemaker && sudo systemctl start corosync

5 Failover Testing

ทดสอบว่า failover ทำงานได้อย่างถูกต้อง

sudo pcs status
sudo pcs resource show
sudo pcs resource move samba-fileserver

ตรวจสอบว่า samba ย้ายไป node อื่นโดยอัตโนมัติ

10 ขั้นตอนที่ 7: Backup & Recovery

การสำรองข้อมูลเป็นสิ่งสำคัญสำหรับ file server ที่สำคัญ บทความนี้จะแนะนำวิธีการ backup Samba

ข้อมูลที่ต้อง backup

  • /etc/samba/smb.conf: ไฟล์ configuration
  • /var/lib/samba/: ข้อมูล registry และ database
  • /var/lib/samba/private/: ข้อมูลความลับ (keys, passwords)
  • /home/ & /srv/samba/: ข้อมูลผู้ใช้และ share

1 Backup Configuration Files

sudo tar -czf /backup/samba-config-$(date +%Y%m%d).tar.gz /etc/samba/
sudo cp /etc/samba/smb.conf /backup/smb.conf.backup

2 Backup Samba Database

สำรองข้อมูล registry และ database ของ Samba

sudo mkdir -p /backup/samba-db && sudo tar -czf /backup/samba-db/samba-$(date +%Y%m%d).tar.gz /var/lib/samba/
sudo regedit -l /var/lib/samba/registry

3 Backup Share Data

สำรองข้อมูลที่แชร์ทั้งหมด

sudo rsync -avz --progress /srv/samba/ /backup/share-data/samba/
sudo tar -czf /backup/share-data/share-$(date +%Y%m%d).tar.gz /srv/samba/

4 Automated Backup Script

# /usr/local/bin/backup-samba.sh
#!/bin/bash
BACKUP_DIR="/backup"
DATE=$(date +%Y%m%d)
# Create backup directories
mkdir -p "$BACKUP_DIR/config"
mkdir -p "$BACKUP_DIR/database"
mkdir -p "$BACKUP_DIR/shares"
# Backup config
tar -czf "$BACKUP_DIR/config/samba-config-$DATE.tar.gz" /etc/samba/
# Backup database
tar -czf "$BACKUP_DIR/database/samba-db-$DATE.tar.gz" /var/lib/samba/
# Backup shares
rsync -avz --delete /srv/samba/ "$BACKUP_DIR/shares/"
# Keep only last 30 days
find "$BACKUP_DIR" -name "*.tar.gz" -mtime +30 -delete
chmod +x /usr/local/bin/backup-samba.sh
crontab -e # Add: 0 2 * * * /usr/local/bin/backup-samba.sh

5 Recovery Procedure

ขั้นตอนการกู้คืนเมื่อเกิดเหตุการณ์ไม่คาดฝัน

1. Stop Samba Services
sudo systemctl stop smbd nmbd winbind
2. Restore Configuration
sudo tar -xzf /backup/samba-config-.tar.gz -C /
3. Restore Database
sudo rm -rf /var/lib/samba/* && sudo tar -xzf /backup/samba-db-.tar.gz -C /
4. Restore Share Data
sudo rsync -avz /backup/share-data/samba/ /srv/samba/
5. Start Services
sudo systemctl start smbd nmbd winbind

11 ขั้นตอนที่ 8: Monitoring & Logging

การการตรวจสอบและ log file เป็นสิ่งสำคัญสำหรับการดูแลระบบ Samba บทความนี้จะแนะนำเครื่องมือและวิธีการต่าง ๆ

1 Samba Logging Configuration

# Add to smb.conf [global] section
log file = /var/log/samba/log.%m
log level = 3
max log size = 1024
syslog = 0
log file = /var/log/samba/log.%I
log file = /var/log/samba/log.smbd
log file = /var/log/samba/log.nmbd

Log Levels: 0 (minimal), 1 (errors), 2 (warnings), 3 (normal), 10 (verbose)

2 Real-time Monitoring with smbstatus

คำสั่ง smbstatus ให้ข้อมูลแบบ real-time เกี่ยวกับ connections

smbstatus
smbstatus -v
smbstatus -L
smbstatus -p
Options:
  • -v: verbose output (PID, name, pid)
  • -L: show locked files
  • -p: show process info
  • -S: show statistics

3 Log Analysis

tail -f /var/log/samba/log.smbd
grep "error" /var/log/samba/log.*
grep "authentication failure" /var/log/samba/log.*
awk '/^\[.*\]/ {print $1}' /var/log/samba/log.* | sort | uniq -c | sort -nr

4 PCP (Performance Co-Pilot)

เครื่องมือ monitoring ขั้นสูงสำหรับ Linux

sudo apt install pcp pcp-webapi pcp-webapp-grafana -y
sudo systemctl enable pmcd && sudo systemctl start pmcd
pmie -t 1s -v /usr/share/pcp/metrics/samba

5 Prometheus & Grafana Integration

# Exporter for Samba metrics
node_exporter
# Samba exporter: https://github.com/mindis/samba_exporter
wget https://github.com/mindis/samba_exporter/releases/download/v0.4.0/samba_exporter-0.4.0.linux-amd64.tar.gz
tar -xzf samba_exporter-*.tar.gz && cd samba_exporter-*
./samba_exporter --samba.address=localhost:445

6 Alerting with netdata

sudo apt install netdata -y

netdata จะแสดง real-time monitoring ของ Samba พร้อม alerts เมื่อมีปัญหา

sudo systemctl enable netdata && sudo systemctl start netdata

เข้าดูที่ http://your-server-ip:19999

12 ขั้นตอนที่ 9: Troubleshooting

เมื่อเกิดปัญหากับ Samba การระบุสาเหตุอย่างรวดเร็วเป็นสิ่งสำคัญ บทความนี้จะแนะนำ diagnostic techniques และ common issues

1 Service Status Check

systemctl status smbd
systemctl status nmbd
systemctl status winbind
journalctl -u smbd -f

Look for: Active: active (running) - if failed, check logs

2 Configuration Validation

testparm
testparm -v

สำคัญ: รัน testparm ก่อน restart service เสมอ!

3 Common Error Messages & Solutions

NT_STATUS_ACCESS_DENIED

สาเหตุที่เป็นไปได้:

  • - File/folder permissions ไม่ถูกต้อง
  • - User ไม่อยู่ใน list ของ valid users
  • - AD group membership ไม่ถูกต้อง
ls -la /path/to/share && getent group "domain users"
NT_STATUS_NETWORK_ACCESS_DENIED

สาเหตุที่เป็นไปได้:

  • - Host allow/deny rules บล็อกการเชื่อมต่อ
  • - Firewall blocking port 445
  • - Network routing issue
iptables -L && sudo ufw status
Connection refused

สาเหตุที่เป็นไปได้:

  • - smbd service ไม่ทำงาน
  • - Port 445 ถูกบล็อก
ss -tlnp | grep 445 && systemctl status smbd

4 Network Connectivity Test

telnet your-server-ip 445
nmblookup -A your-server-ip
smbclient -L your-server-ip -N

-N: ไม่ใส่ password (anonymous)

5 AD Integration Troubleshooting

realm list
kinit administrator@example.com
klist
wbinfo -t

-t: Test DC trust relationship

6 Debug Mode

sudo smbd -i -s -d 3
sudo nmbd -i -d 3

-i: Run in foreground (don't detach) -d: Debug level (1-10)

7 Logs Location

Main log
/var/log/samba/log.smbd
NetBIOS log
/var/log/samba/log.nmbd
Per-client log
/var/log/samba/log.
Winbind log
/var/log/winbindd/winbindd.log

13 ตัวอย่างการใช้งานจริง (Use Cases)

บทความนี้จะแสดงตัวอย่างการตั้งค่า Samba แบบจริงสำหรับองค์กรต่าง ๆ

Use Case 1: Corporate File Server

องค์กรขนาดกลางที่ม nhân 100-500 คน ต้องการ file server ที่แชร์เอกสารและสร้างสภาพแวดล้อมทำงานร่วมกัน

Architecture:

Infrastructure: Ubuntu 22.04 LTS, 8-core CPU, 32GB RAM, 2TB SSD

AD Integration: Join to existing AD domain, all users authenticated via AD

Shares Setup:

[global]
security = ADS
workgroup = CORP
realm = CORP.EXAMPLE.COM
# Department shares
[Departments]
path = /srv/samba/departments
valid users = @CORP"domain users"
writable = yes
force group = domain users
create mask = 0664
directory mask = 0775
inherit permissions = yes
# Public shares
[Public]
path = /srv/samba/public
browsable = yes
guest ok = yes
read only = yes

Use Case 2: Medical Records System

โรงพยาบาลเล็กที่ต้องการแชร์เอกสารทางการแพทย์ระหว่างแผนกต่าง ๆ

Requirements:

  • Security: HIPAA compliance - ต้องมี encryption และ audit logging
  • Access Control: Role-based permission per department
  • Backup:Daily backups with 30-day retention
  • HA: High availability for critical system

Configuration Highlights:

## Medical Records Shares
[MedicalRecords]
path = /data/medical-records
valid users = @CORP"doctors" @CORP"nurses" @CORP"admin"
writable = yes
force group = medical-staff
create mask = 0640
directory mask = 0770
encryption = required
veto files = /*.exe/*.dll/*.bat/*.cmd/
## Audit Logs
log level = 4
log file = /var/log/samba/medical-records.log.%I

Access Control by Department:

Doctors

Full access to all departments

Nurses

Patient files + Medication records

Admin

Reports + Billing + HR

Patients (Read-Only)

Own medical records only

Use Case 3: University Department Shares

มหาวิทยาลัยที่มีหลายคณะ ต้องการแชร์ไฟล์ในแต่ละคณะและมีระบบจัดการนักศึกษา

Structure:

# University Department Shares
[Dept-ComputerScience]
path = /srv/samba/depts/computer-science
valid users = @UNIV"cs-faculty" @UNIV"cs-students"
writable = yes
force group = computer-science
create mask = 0664
directory mask = 0775
# Student Project Space
[StudentProjects]
path = /srv/samba/projects
valid users = @UNIV"students"
writable = yes
force user = %U
create mask = 0600
directory mask = 0700
# Course Materials (Read-only)
[CourseMaterials]
path = /srv/samba/courses
browsable = yes
valid users = @UNIV"all"
read only = yes
guest ok = yes

Quota Management:

ตั้ง quota สำหรับนักศึกษาเพื่อป้องกันการใช้พื้นที่เกินขอบเขต

## Per-user quota (5GB)
sudo setquota -u studentID 1048576 1153434 100 110 /srv/samba/projects
## Group quota (50GB)
sudo setquota -g cs-students 10485760 11534336 100 110 /srv/samba/projects

Use Case 4: Manufacturing Production Data

โรงงานอุตสาหกรรมที่ต้องการ collect ข้อมูลจากเครื่องผลิตและแชร์รายงานระหว่างแผนก

Requirements:

  • Real-time:ต่ำ latency access for production lines
  • Capacity: Large storage for historical data (10TB+)
  • Security: Only authorized machines can write
  • Reliability: 99.9% uptime with HA

Configuration:

## Production Data Shares
[ProductionData]
path = /data/production
browsable = no
write list = @MANF"machine1" @MANF"machine2" @MANF"qc"
read list = @MANF"supervisors" @MANF"management"
create mask = 0660
directory mask = 0770
hide file = *.tmp/*.log/*.bak
## Shift Reports
[ShiftReports]
path = /data/reports
browsable = yes
valid users = @MANF"supervisors"
writable = yes
force group = reporting
create mask = 0664
directory mask = 0775

14 สรุปและขั้นตอนถัดไป

Key Takeaways

Understanding Samba Architecture

Samba ทำงานบน SMB/CIFS protocols ด้วย processes หลัก 3 ตัว: smbd, nmbd, winbind

Security is Critical

อย่าลืม disable SMBv1, enable signing, restrict anonymous access

AD Integration Power

Samba ผสานรวมกับ AD ได้อย่างสมบูรณ์ จัดการผู้ใช้แบบรวมศูนย์

High Availability Matters

สำหรับ production, ตั้งค่า HA ด้วย DRBD + Pacemaker หรือ CephFS

Samba vs Alternatives

Feature Samba NFS Cloud Storage
Cross-platform Excellent Moderate Good
Performance Excellent Excellent Variable
Cost Free Free Subscription
Security Excellent Moderate Excellent
Complexity High Medium Low

Next Steps for Advanced Learning

References & Resources

Official Documentation

https://www.samba.org/samba/docs/

Samba Wiki

https://wiki.samba.org

GitHub Repository

https://github.com/samba-team/samba

Mailing List

samba-technical@samba.org