การใช้งาน SAMBA เป็นไฟล์เซอร์ฟเวอร์ให้กับองค์กร

จาก Research 2549, สารานุกรมฟรี

สารบัญ

กล่าวนำ

  • ในที่นี้ใช้ระบบปฏิบัติการ Linux Ubuntu 6.0.6
  • Samba ใช้คอนฟิกไฟล์ใน /etc/samba/smb.conf
  • ตัวอย่างไฟล์คอนฟิกที่มากับการติดตั้ง http://research.crma.ac.th/2549/images/0/0f/Smb.conf

การติดตั้ง และปรับแต่งค่า

ติดตั้ง Samba เซอร์ฟเวอร์

sudo  apt-get  install  samba

ในกรณีที่มีปัญหาในการติดตั้ง ให้ทดลองอัพเดทไฟล์ และติดตั้งด้วย aptitude

sudo apt-get update
sudo aptitude reinstall samba

หรือหากยังไม่ได้ทำการติดตั้งให้ทำการติดตั้งใหม่ด้วยคำสั่ง

sudo aptitude install samba

ตรวจสอบดูว่าเดม่อนของ Samba รันอยู่หรือไม่ prachya@fujitablet:~$ ps -ef |grep smb

root      6892     1  0 10:22 ?        00:00:00 /usr/sbin/smbd -D
root      6893  6892  0 10:22 ?        00:00:00 /usr/sbin/smbd -D
root      7017  6892  0 10:26 ?        00:00:00 /usr/sbin/smbd -D
prachya   7073  6031  0 10:28 pts/0    00:00:00 grep smb
prachya@fujitablet:~$

หรือในกรณีที่เครื่องติดตั้ง nmap ไว้แล้วให้ลองแสกนพอร์ตด้วยคำสั่ง nmap localhost

prachya@fujitablet:~$ nmap localhost
Starting Nmap 4.10 ( http://www.insecure.org/nmap/ ) at 2006-11-10 10:29 ICT
Interesting ports on localhost (127.0.0.1): 
Not shown: 1674 closed ports
PORT     STATE SERVICE
80/tcp   open  http
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
631/tcp  open  ipp
3306/tcp open  mysql

Samba จะใช้พอร์ต 139 และ 445 เพื่อเปิดทางให้โปรโตคอลสำหรับแชร์ไฟล์

สร้างไดเร็กทอรี่สำหรับแชร์ไฟล์

โจทย์ 1: ต้องการแชร์ไฟล์ในไดเร็กทอรี่ /home/public

  • ขั้นตอนต่อไปเป็นการสร้างไดเร็กทอรี่สำหรับการแชร์ไฟล์ สำหรับทุกคน
sudo  mkdir  /home/public
sudo  chown  nobody:nogroup  /home/public
sudo  chmod  777  /home/public
  • แก้ไขไฟล์ /etc/samba/smb.conf ให้มีรายละเอียดดังนี้
[global]
workgroup = MYGROUP
...
[public]
path = /home/public
public = yes 
writable = yes
printable = no
  • เริ่มการทำงานของ Samba ใหม่
root@fujitablet:~# /etc/init.d/samba restart
 * Stopping Samba daemons...                                             [ ok ]
 * Starting Samba daemons...
  • จากนั้นให้ทดสอบการทำงานของ Samba ด้วยการใช้ network browser ของวินโดวส์ หรือ Linux จะพบว่ามีเครื่องที่เป็น Samba เซอร์ฟเวอร์ปรากฏใน workgroup และสามารถใช้ไดเร็กทอรี่ public ได้

โจทย์ 2: ต้องการแชร์ไฟล์ในบางไดเร็กทอรี่ให้เครื่องลูกข่าย โดยต้องมีการล็อกอิน

  • แก้ไข/เพิ่มรายละเอียดการติดตั้งในไฟล์ /etc/samba/smb.conf
[global]
workgroup = it4502
server string = Ubuntu Server
hosts allow = 10.134. 127.
security = user
load printers = yes
;guest account = nobody
log file = /var/log/samba.%m 
max log size = 50
encrypt passwords = yes
null passwords = no
local master = yes
os level = 33
;domain master = yes
;preferred master = yes
;domain logons = yes
;logon script = %G.bat
#============================ Share Definitions ==============================
[source-code]
comment = Repositories of source code
path = /home/src
create mask =0640
directory mask = 750
valid users = @it4502, prachyac
public = yes
writable = yes
[Media]
comment = Repositories for multimedia stuff
path = /home/media/
available = yes
browseable = yes
public = yes
  • เริ่มการทำงานของ Samba ใหม่
root@fujitablet:~# /etc/init.d/samba restart
 * Stopping Samba daemons...                                             [ ok ]
 * Starting Samba daemons...

สร้าง User และรหัสผ่าน

สร้าง user สำหรับ Unix แอ็คเคาท์

root@fujitablet:~# adduser prachyac

โปรแกรมจะให้กรอกข้อมูลพื้นฐานของ user รวมถึงรหัสผ่าน

Adding user `prachyac'...
Adding new group `prachyac' (1003).
Adding new user `prachyac' (1003) with group `prachyac'.
Creating home directory `/home/prachyac'.
Copying files from `/etc/skel'
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for prachyac
Enter the new value, or press ENTER for the default
       Full Name []: Prachya Chalermwat
       Room Number []: Instructor Room
       Work Phone []: 6-2888
       Home Phone []: 6-2669
       Other []:
Is the information correct? [y/N] y

จากนั้นให้เพิ่มชื่อ user ในฐานข้อมูลของ Samba ด้วยคำสั่ง smbpasswd

root@fujitablet:~# sudo smbpasswd -a prachyac
New SMB password:
Retype new SMB password:
Added user prachyac.

การทำให้ Samba เป็น DC (Domain Controller)

References

การใช้งานฝั่งเครื่องลูกข่าย

เครื่องลูกข่าย Linux

เครื่องลูกข่าย Windows

เครื่องลูกข่าย Mac

References

อ้างอิงเว็บไซต์ไทย

Personal tools