
ทำได้ครับ ปกติก็เป็นเช่นนั้นอยู่แล้ว ผมไม่เห็นต้องไป Add user ของ Samba ต่างหากเลยถ้ามี User account ของระบบอยู่แล้ว
ผมว่า น่าจะมีอะไรผิดพลาดใน smb.conf นะครับ
รบกวนช่วยเอา smb.conf มาให้ดูหน่อยครับ ผมจะดูว่าผิดพลาดตรงไหนครับ

อ้อ.. ถ้าจะให้ผมหาที่มาของปัญหาง่ายกว่านั้น ขออีก 2 ไฟล์ครับ
เอา /etc/passwd มาด้วยครับ ผมจะรายชื่อ User
แล้วก็เอา /etc/hosts มาด้วยครับ เผื่อคุถณกหนด host allow ด้วย ผมจะได้แนะนำให้มันสอดคล้องกับไฟล์ hosts
อาจยังมีไฟล์อื่นต้องดูอีก แต่ขอ 3 ไฟล์หลักนี่มาดูก่อนครับ

คือว่า ผมใช้ Linux Redhat 9.0 แล้ว Install แบบ Server ครับ
จากนั้น ผมก็สร้าง Folder ขึ้นมา ชื่อ data ไว้ที่ /data เลยนะครับ
แล้วกำหนด permission ให้ /data ว่าให้ ใช้ได้แค่ Owner กับ Group ครับ
โดย Owner เป็น root และ Group เป็น user001
โดย user001 ผมสร้างใน User Manager แล้วครับ
จากนั้น ผมก็ไป Share จาก Samba ครับ ปรากฎว่า
พอ user001 Login จาก Windows XP กรอก Password เรียบร้อย
พอจะเข้า Folder ที่ Share จาก Linux มันก็ไม่ยอมให้เข้าครับ
มันจะขึ้น Dialog ให้ใส่ Password ตลอดเลยครับ
ผมเลยคิดว่า Samba มันแยก User ออกจาก Linux น่ะครับ
เพราะ user001 เวลามองผ่าน Network ก็ยังเห็น Folder
ที่ Linux สร้างให้ user001 แต่เข้าใช้งานไม่ได้เช่นกันครับ
คล้ายๆ กับว่า Samba ไม่มี Password ของ user001
จึงตรวจสอบ Password แล้วไม่ผ่าน น่ะครับ
ไม่รู้ว่าผมต้องไปตั้ง Parameter ตรงไหนอีก ครับ
อ้อ.. ผมใช้ Samba Setting ที่เป็น GUI ครับ
พอดีตอนนี้ไม่สามารถเอา File passwd เป็น host มาครับ
ขอบคุณครับ

โอเคครับ ทำให้ตีวงปัญหาได้แคบลงไปอีกหน่อย
แต่อย่างไรก็อยากขอดูไฟล์ /etc/samba/smb.conf ครับ
แล้วก็ /etc/host ไม่ต้องก็ได้ครับ เดี๋ยวเปิด allow มันหมดเลยใน smb.conf ก็ได้
จากข้อมูลที่บอกเพิ่มมา ทำให้ผมไม่ต้องการดูไฟล์ passwd แล้วครับ
ยังเหลือที่อาจเป็นปัญหาได้อีก 4 ประการคือ
1. เรื่อง password encryption
2. เรื่อง host allow
3. เรื่อง Firewall (ไม่ได้เปิด port 139 และ 445 ที่ server ไว้)
4. permission ของ directory ที่แชร์ เพราะที่คุณบอกมา คุณยังไม่ได้บอก permission ครับ บอกมาแค่เป็น user อะไร group อะไร แต่ผมอยากทราบว่า คุณให้ permission กับ group เป็นอะไรครับ
อย่างไรก็ตาม ผมถนัด config ที่ไฟล์ smb.conf ถ้าเอาไฟล์นั้นมาดูได้ ผมน่าจะเจอปัญหาได้ง่ายกว่าครับ
สองสามวันผมจะตรวจดูกระทู้ทีหนึ่งนะครับ

อืม .. เท่าที่ผมจำได้ ปรกติ samba user กับ system user เนี่ย จะแยกเก็บกันนะครับ
แต่ที่จำได้ รู้สึกจะมีคำสั่งให้ gen user จาก system user ได้นะครับ :)
แต่อย่างไรก็ตาม คงต้องดูตั้งแต่สิทธิของ folder ที่เครื่อง linux ด้วย เรื่องของ firewall อะไรต่างๆ เนี่ย ก็ต้องดูเหมือนกัน แต่เบื้องต้นผมว่า ลองปิด firewall ดู add samba user ดู แล้วลองดูว่าเห็น share folder ไม้ login เข้าได้ไม้ก่อนนะครับ ถ้าเข้าได้ แต่อ่าน-เขียนไม่ได้เนี่ย อาจจะเป็นเพราะ local folder permission ก็เป็นได้ครับ :)

# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command "testparm"
# to check that you have not made any basic syntactic errors.
#
#======================= Global Settings =====================================
[global]
# workgroup = NT-Domain-Name or Workgroup-Name
workgroup = WORKGROUP
# server string is the equivalent of the NT Description field
server string = linux server
# This option is important for security. It allows you to restrict
# connections to machines which are on your local network. The
# following example restricts access to two C class networks and
# the "loopback" interface. For more examples of the syntax see
# the smb.conf man page
; hosts allow = 192.168.1. 192.168.2. 127.
# if you want to automatically load your printer list rather
# than setting them up individually then you'll need this
printcap name = /etc/printcap
load printers = yes
# It should not be necessary to spell out the print system type unless
# yours is non-standard. Currently supported print systems include:
# bsd, sysv, plp, lprng, aix, hpux, qnx, cups
printing = cups
# Uncomment this if you want a guest account, you must add this to /etc/passwd
# otherwise the user "nobody" is used
# this tells Samba to use a separate log file for each machine
# that connects
log file = /var/log/samba/%m.log
# Put a capping on the size of the log files (in Kb).
max log size = 0
# Security mode. Most people will want user level security. See
# security_level.txt for details.
security = SHARE
# Use password server option only with security = server
# The argument list may include:
# password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
# or to auto-locate the domain controller/s
# password server = *
; password server = <NT-Server-Name>
# Password Level allows matching of _n_ characters of the password for
# all combinations of upper and lower case.
; password level = 8
; username level = 8
# You may wish to use password encryption. Please read
# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation.
# Do not enable this option unless you have read those documents
smb passwd file = /etc/samba/smbpasswd
# The following is needed to keep smbclient from spouting spurious errors
# when Samba is built with support for SSL.
; ssl CA certFile = /usr/share/ssl/certs/ca-bundle.crt
# The following are needed to allow password changing from Windows to
# update the Linux system password also.
# NOTE: Use these with 'encrypt passwords' and 'smb passwd file' above.
# NOTE2: You do NOT need these to allow workstations to change only
# the encrypted SMB passwords. They allow the Unix password
# to be kept in sync with the SMB password.
unix password sync = No
passwd program = /usr/bin/passwd %u
passwd chat = *New*password* %n\n *Retype*new*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*
# You can use PAM's password change control flag for Samba. If
# enabled, then PAM will be used for password changes when requested
# by an SMB client instead of the program listed in passwd program.
# It should be possible to enable this without changing your passwd
# chat parameter for most setups.
pam password change = yes
# Unix users can map to different SMB User names
; username map = /etc/samba/smbusers
# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting
; include = /etc/samba/smb.conf.%m
# This parameter will control whether or not Samba should obey PAM's
# account and session management directives. The default behavior is
# to use PAM for clear text authentication only and to ignore any
# account or session management. Note that Samba always ignores PAM
# for authentication in the case of encrypt passwords = yes
obey pam restrictions = yes
# Most people will find that this option gives better performance.
# See speed.txt and the manual pages for details
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
# Configure Samba to use multiple interfaces
# If you have multiple network interfaces then you must list them
# here. See the man page for details.
; interfaces = 192.168.12.2/24 192.168.13.2/24
# Configure remote browse list synchronisation here
# request announcement to, or browse list sync from:
# a specific host or from / to a whole subnet (see below)
; remote browse sync = 192.168.3.25 192.168.5.255
# Cause this host to announce itself to local subnets here
; remote announce = 192.168.1.255 192.168.2.44
# Browser Control Options:
# set local master to no if you don't want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
; local master = no
# OS Level determines the precedence of this server in master browser
# elections. The default value should be reasonable
; os level = 33
# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don't use this
# if you already have a Windows NT domain controller doing this job
; domain master = yes
# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
; preferred master = yes
# Enable this if you want Samba to be a domain logon server for
# Windows95 workstations.
; domain logons = yes
# if you enable domain logons then you may want a per-machine or
# per user logon script
# run a specific logon batch file per workstation (machine)
; logon script = %m.bat
# run a specific logon batch file per username
; logon script = %U.bat
# Where to store roving profiles (only for Win95 and WinNT)
# %L substitutes for this servers netbios name, %U is username
# You must uncomment the [Profiles] share below
; logon path = \\%L\Profiles\%U
# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server
; wins support = yes
# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
; wins server = w.x.y.z
# WINS Proxy - Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one WINS Server on the network. The default is NO.
; wins proxy = yes
# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups. The built-in default for versions 1.9.17 is yes,
# this has been changed in version 1.9.18 to no.
guest ok = yes
encrypt passwords = yes
dns proxy = no
# Case Preservation can be handy - system default is _no_
# NOTE: These can be set on a per share basis
; preserve case = no
; short preserve case = no
# Default case is normally upper case for all DOS files
; default case = lower
# Be very careful with case sensitivity - it can break things!
; case sensitive = no
#============================ Share Definitions ==============================
[homes]
comment = Home Directories
browseable = no
writeable = yes
valid users = %S
create mode = 0664
directory mode = 0775
# If you want users samba doesn't recognize to be mapped to a guest user
; map to guest = bad user
# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
; comment = Network Logon Service
; path = /usr/local/samba/lib/netlogon
; guest ok = yes
; writable = no
; share modes = no
# Un-comment the following to provide a specific roving profile share
# the default is to use the user's home directory
;[Profiles]
; path = /usr/local/samba/profiles
; browseable = no
; guest ok = yes
# NOTE: If you have a BSD-style print system there is no need to
# specifically define each individual printer
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
# Set public = yes to allow user 'guest account' to print
printable = yes
# This one is useful for people to share files
;[tmp]
; comment = Temporary file space
; path = /tmp
; read only = no
; public = yes
# A publicly accessible directory, but read only, except for people in
# the "staff" group
;[public]
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = @staff
# Other examples.
#
# A private printer, usable only by fred. Spool data will be placed in fred's
# home directory. Note that fred must have write access to the spool directory,
# wherever it is.
;[fredsprn]
; comment = Fred's Printer
; valid users = fred
; path = /home/fred
; printer = freds_printer
; public = no
; writable = no
; printable = yes
# A private directory, usable only by fred. Note that fred requires write
# access to the directory.
;[fredsdir]
; comment = Fred's Service
; path = /usr/somewhere/private
; valid users = fred
; public = no
; writable = yes
; printable = no
# a service which has a different directory for each machine that connects
# this allows you to tailor configurations to incoming machines. You could
# also use the %U option to tailor it by user name.
# The %m gets replaced with the machine name that is connecting.
;[pchome]
; comment = PC Directories
; path = /usr/local/pc/%m
; public = no
; writable = yes
# A publicly accessible directory, read/write to all users. Note that all files
# created in the directory by users will be owned by the default user, so
# any user with access can delete any other user's files. Obviously this
# directory must be writable by the default user. Another user could of course
# be specified, in which case all files would be owned by that user instead.
;[public]
; path = /usr/somewhere/else/public
; public = yes
; only guest = yes
; writable = yes
; printable = no
# The following two entries demonstrate how to share a directory so that two
# users can place files there that will be owned by the specific users. In this
# setup, the directory should be writable by both users and should have the
# sticky bit set on it to prevent abuse. Obviously this could be extended to
# as many users as required.
;[myshare]
; comment = Mary's and Fred's stuff
; path = /usr/somewhere/shared
; valid users = mary fred
; public = no
; writable = yes
; printable = no
; create mask = 0765
[data]
path = /data
writeable = yes
guest ok = yes
[test]
path = /test
valid users = user001
writeable = yes

เอาล่ะครับ เรามาดูกัน คุณ somdej ดูด้วยนะครับ เพราะว่า samba user กับ system user ไม่ต้องแยกกันก็ได้ครับ แต่มันอยู่ที่ตรง ตามผมมาครับ...
จากที่คุณเอา smb.conf ให้ผมดู มีที่เตะตาผมอยู่ดังนี้ครับ
(ผมจะยกเอาเฉพาะบรรทัดนั้นๆ มานะครับ)
; hosts allow = 192.168.1. 192.168.2. 127.
มี comment เอาไว้หน้า แบบนี้แสดงว่าไม่กำหนดเลย แสดงว่าจะเปิดหมดให้ทุกเครื่องติดต่อหรือเปล่าครับ ถ้าไม่ใช่ ก็ควรระบุตรงนี้ด้วยก็จะทำให้ระบบปลอดภัยมากขึ้นครับ
security = SHARE
นี่ล่ะครับ 1 ในสาเหตุของปัญหา (แปลว่ายังมีสาเหตุอื่่นอีก) ตรงนี้เพราะคุณต้องการบริหารตาม User ก็ต้องกำหนดเป็นแบบ user ครับ ไม่ใช่ share
pam password change = yes
obey pam restrictions = yes
นี่อีกครับ อีก 2 ในสาเหตุของปัญหา (ยังมีอีก) กำหนดเป็น no เสียทั้งคู่ครับ เราไม่ควรอนุญาตให้มีการเปลี่ยน password ผ่าน SMB ได้
; local master = no
นี่ก็เกี่ยวบ้าง กรณีที่ Server นี้ของคุณเป็นตัวเดียวในระบบ คือไม่มีพี่ Windows อยู่ด้วย หรือถึงมีก็กำหนดเป็น yes ได้ก็จะทำให้ Client หา Server ได้เจอง่ายกว่าครับ
; preferred master = yes
อันนี้ กำหนดเป็น Auto เสียครับ ถ้าไม่มีพี่ Windows อยู่ในระบบ SAMBA จะได้เป็น master เสียเองเลย
guest ok = yes
อันนี้ แค่จะถามว่า แน่ใจนะครับ....
encrypt passwords = yes
อันนี้เป็น no จะปัญหาน้อยกว่านะครับ (หมายถึง จะยังมีปัญหาได้กับ Windows Me, 9x เท่านั้น)
ต่อไป ผมจะให้ดูตัวอย่างการแชร์โดยเอาของคุณมาปรับแต่งให้ครับ
[data]
path = /data
readlist = ยูสเซอร์ @กรุ๊ป
write list = ยูสเซอร์ @กรุ๊ป
force group = กรุ๊ป
force user = ยูสเซอร์
guest ok = yes
ตรง ยูสเซอร์ ก็ให้ใส่ user ที่ต้องการได้เลยครับ ถ้ามีหลายคนก็เว้นวรรคก่อนแล้วชื่อต่อไป แต่ที่จริง ผมแนะนำให้ทำเป็น Group ครับ แล้วใส่เป็น @กรุ๊ป แทน ดีกว่าใส่เป็น User ครับ ยกตัวอย่างเช่น ไดเร็คทอรี่ผมชื่อ PO ไว้เก็บไฟล์ Purchase order ซึ่งสร้างจาก Calc ผมจึงจัดแจงแชร์ แล้วเปิดให้ write list = @po_rw แล้วผมก็จัดแจงสร้างกรุ๊ปชื่อ po_rw ขึ้น แล้วคนไหนที่จะให้เขาเขียนไฟล์ลงในไดเร็คทอรี่นี้ได้ ผมก็จัดแจง add เขาเป็นสมาชิกในกรุ๊ป po_rw ด้วย ทำให้ผมไม่ต้องมายุ่งกับ smb.conf บ่อยๆ แต่จัดการที่ System user อย่างเดียวเพียวๆ เลย รวมทั้ง permission ของไดเร็คทอรี่ PO ผมก็กำหนดแบบเดียวกันคือ Group เป็น po_rw แล้วให้สิทธิเขียน/อ่าน/เข้าถึงได้ เวลาเพิ่ม User อีกก็ไม่ต้องวุ่นวายอะไรอีก ก็แค่ให้ User ใหม่นั้นเป็นสามชิกในกรุ๊ป po_rw ด้วย หรือจะเอาใครออกก็ง่ายอีกเหมือนกัน แค่ Click 5 ครั้งเท่านั้น (นับตั้งแต่คลิ๊กเรียก User manager ขึ้นมากำหนดจนถึงปิดโปรแกรม)
แล้วก็ อย่าลืมกำหนด read list ด้วยนะครับ ถ้ากำหนด write list เพียงอย่างเดียวจะเกิดเหตุการณ์คือ เข้าไปดูในไดเร็คทอรี่ที่แชร์ไว้แล้ว ไม่เห็นไฟล์อะไรเลยทั้งๆ ที่เข้าได้ แต่สามารถก๊อปปี้ไฟล์เข้าไปใส่ได้ด้วย แต่ก๊อปปี้เสร็จแล้ว มองไม่เห็น เหมือนไม่มีไฟล์เลย
แต่ group หรือ user mี่มีรายชื่ออยู่ใน read list แล้ว อาจไม่จำเป็นต้องมีรายชื่ออยู่ใน write list ก็ได้นะครับ ถ้าต้องการให้เขาอ่านได้อย่างเดียว
เช่นกรณีตัวอย่างไดเร็คทอรี่ PO ที่ผมยกให้เห็น ผมจะมีกรุ๊ปสองตัวคือ po_read และ po_rw ครับ แล้วก็กำหนดให้ read list = @po_read
write list = @po_rw
แล้ว user คนไหนที่จะให้อ่านได้ (รวมทั้งคนที่เขียนได้ด้วย) ก็ให้เป็นสมาชิกใน po_read หมด
แต่เฉพาะ user ที่จะให้เขียนได้เท่านั้น ที่จะให้เป็นสมาชิกใน po_rw ด้วยครับ
นี่เป็นแนวคิดในการจัดการแบบ Set ครับ
ต่อมาเรื่อง force user ก็คือ บังคับให้ไฟล์หรือไดเร็คทอรี่ใดๆ ที่จะถูดใส่/เขียนเข้ามามี owner เป็นตามที่กำหนด ตรงนี้ไม่ค่อย strict เท่าไหร่ครับ ไม่กำหนดก็ได้ แต่....
ถ้าทำตามแนวคิดแบบ Set ที่ผมแนะนำแล้ว force group จำเป็นต้องกำหนดครับ เพื่อให้ไฟล์และไดเร็คทอรี่ที่จะถูกใส่เข้ามาควรเป็นของกรุ๊ปที่อ่าน/เขียนได้ กรณีตามตัวอย่างที่ผมให้ดู ตรงนี้ผมจะกำหนดเป็น
force group = po_rw (ไม่ต้องมี @)
นอกจากนี้ ควรกำหนด force create mode และ force directory mode ด้วยครับ ผมไม่ได้ยกตัวอย่างมา ลองซนดูแล้วกันครับ เข้าใจไม่ยาก
ตัวอย่างต่อไปซึ่งปรับแต่งมาจากของคุณครับ
[test]
path = /test
read list = user001
write list = user001
force group = กรุ๊ป
force user = ยูสเซอร์
ก็ลักษณะเดียวกันครับ Server ที่ผมเป็นคน Set เองทุกตัว ผมจะจัดเป็น Group ตาม Directory ที่แชร์เสมอ บริหารง่ายที่สุดครับ และการทำแบบนี้ อย่าลืมเรื่อง Permission ของตัว Directory ที่แชร์อยู่ด้วยนะครับ การทำแบบนี้ ดีตรงที่ ทำทีเดียวครับ มีผลไปหมด
คือ... ทำให้ Permission ของ NFS ก็ถูกต้องไปด้วย เพราะ Client บางเครื่องของผม ไม่ได้ Access Server ผ่าน SMB ครับ บางเครื่องใช้ NFS แต่มันก็จะให้ผลถูกต้องตาม Permission ของ Group ที่ User นั้นๆ เป็นสมาชิกอยู่ไปด้วยนั่นเอง
ยังมีปัญหาอื่นที่อาจมีได้ยังไม่ได้พูดถึงอยู่นะครับ ลองไปปรับแต่งตามนี้ก่อนครับ ถ้าปรับแล้ว Windows XP ขึ้นไปสามารถเข้าถึงได้เลย ก็แสดงว่าไม่มีปัญหาอื่นแล้ว แต่ถ้าเป็น Windows Me, 9x ล่ะก็... ยังมีอีกปัญหาครับ ที่ต้องแก้ไข... ถ้าเจอ... ก็มาถามอีกแล้วกันครับ
วันนี้ขอตอบแค่นี้ก่อนนะครับ... พิมพ์ยาว... มันเหนื่อย... ขอผมพักผ่อนบ้าง ไม่ว่ากันนะครับ กลัวใจร้อน.. ใจจริงก็อยากเล่าหมดเหมือนกัน...แต่ไม่ไหว... รวดเดียวไม่ไหวครับ

โอ๊ยๆ... ขอโทษครับ ยังมีอีกเรื่องคือ printer น่ะครับ คุณตั้งใจจะแชร์ printer ด้วยหรือเปล่าครับ ถ้าไม่ใช่ ให้ no เสีย แล้วเอาในส่วน [printers] ออกเสียให้หมด ลดภาระครับ แต่ถ้าใช่ คือถ้าคุณต่อ printer กับ Server เอาไว้แล้วเปิดแชร์ด้วยล่ะก็... ที่ผมเห็นก็ยังกำหนดไม่ถูกต้องครับ
แล้วที่ถูกต้องเป็นยังไงหรือ... ตอบผมมาก่อนแล้วกันครับ ถ้าคุณแชร์ printer ด้วยหรือเปล่า ผมไม่อยากเล่าก่อน... เมื่อยมือแล้วคร้าบ....

โอ๊ยๆ... อีกทีครับ
workgroup = WORKGROUP
ตรงนี้ อย่าลืมนะครับ ผมเห็นเป็น WORKGROUP เข้าใจว่าคุณยังไม่ได้กำหนด ดูมันเหมือนเป็นค่า default อยู่
ถ้าจะให้มันเข้ากลุ่มกับพี่ Windows ทั้งหลายหรือเครื่องอื่นใด ก็อย่าลืมให้แกอยู่ถูก workgroup ด้วยครับ
ลาล่ะ....ไว้พรุ่งนี้มาดูใหม่ครับ (ไปจริงแล้ว)

ขอบคุณ คุณจักรนันท์ มากๆๆๆ ครับ
ทีแรกผมก็พยายามจะใช้แนว Concept ที่กำหนด Permission โดย User Manager
และไปกำหนด Owner และ Group เข้าถึงที่ Folder คือ จะไม่กำหนด User ใน Samba ครับ
ทีแรกก็คิดว่ามันจะง่ายๆ คือ Samba มันน่าจะมอง User และ Group จาก User Manager
แต่ปรากฎว่า Samba มันมองเห็น User จริงๆ คือ เวลาเปิดดู Network จาก Windows XP
ผมจะเห็น Folder ที่ Samba Share ให้ และเห็น Folder ที่เป็นชื่อของ User นั้นๆ ด้วย
แต่ว่า เข้ายังไงก็เข้าไม่ได้ ติดตรงให้ใส่ Password ตลอดเลยครับ ใส่ถูกต้องก็บอกว่าผิด
จนดูเหมือนว่า Samba เห็น User แต่ไม่เห็น Password ครับ
แล้วผมก็พยายาม Set ค่า ก็มั่วๆ เอาครับ เปิดหนังสือบ้าง หาจากเวปบ้าง
แต่ไม่เห็นมีบอกเกี่ยวกับการกำหนด User Password แบบ Group ด้วย User Manager
และในบางกระทู้ หรือบางเวป จะบอกไว้ว่า User ของ Linux กับ Samba จะแยกกัน
สุดท้าย ผมก็ต้อง Add User และ Password ใน Samba ครับ
ก็สามารถใช้งานได้ทันทีครับ มี Permission ด้วย แต่ว่า มันเป็น Permission ในระดับ User ครับ
มันไม่สามารถควบคุม Permission เป็นแบบ Group น่ะครับ
ตรงที่ คุณจักรนันท์ แนะนำมาผมจะไปลองทำดูนะครับ ตกลงมีส่วนที่ผมต้อง Set และ
ทำความเข้าใจกับมัน ก็คือ
security = SHARE ต้องเปลี่ยนเป็น USER เพื่อการบริหารตาม User
pam password change = yes ต้องเป็น No อันนี้ผมก็ลองผิดลองถูกมาจนงงไปหมดแล้วครับ
obey pam restrictions = yes ต้องเป็น No อันนี้ก็คงเกี่ยวกับ PAM ใช่ไหมครับ
(ทั้งๆ ที่ไม่รู้หรอกว่า PAM คืออะไร ฮ่าๆๆ คงเกี่ยวกับการจัดการ Password ล่ะมั้งครับ)
encrypt passwords = yes เปลี่ยนเป็น No อะไรก็ไม่รู้ แต่ต้องเกี่ยวกับ Password แน่ๆ
hosts allow = 192.168.1. 192.168.2. 127.
ตรง host allow ผมไม่ค่อยเข้าใจอ่ะครับว่า มันเกี่ยวอะไรกับการกำหนด Permission หรือตรวจสอบ
User Password ของ Samba ผมก็งงๆ ตอนแรกว่า คุณจักรนันท์ จะขอดูไฟล์ host ทำไม
ลองเปิดดูก็เป็น IP Address นี่นา แต่ก็จะลองเอาไปทำตามที่แนะนำครับ
[data]
path = /data
readlist = @mygroup สมมุติว่าผมตั้ง mygroup อยู่ใน User Manager นะครับ
write list = @mygroup
guest ok = yes
จากนั้นผมก็ไปสร้าง user001 อยู่ใน mygroup ใน User Manager
แล้วก็กำหนด Folder /data ให้มี Permission ให้ Owner เป็น root และ Group เป็น mygroup
Other ไม่กำหนดให้อ่านเขียน
เรื่อง Printer ผมไม่มีครับ คงจะให้เป็นค่า Default ของ Samba ไป หรืออาจจะลบออก
เรื่อง Workgroup = ชื่อ Workgroup พอดีผมแก้ไขชื่อให้มันตรงกับของ Windows น่ะครับ
ตกลงมี Parameter หลักๆ เท่านี้ใช่ไหมครับ แล้วผมไม่ต้อง Add User ใน Samba ด้วยใช่ไหมครับ
ผมจะลองเอาไปทำตามคำแนะนำครับ ต้องขอขอบคุณ คุณจักรนันท์ มากๆๆ อีกครับ
รบกวนคุณจักรนันท์ มากเลยครับ ..ถ้าผมทำได้แล้วผมจะนำความรู้ไปเผยแพร่บอกต่อด้วยครับ

มาครับ มาต่อกัน...
>> encrypt passwords = yes เปลี่ยนเป็น No อะไรก็ไม่รู้ แต่ต้องเกี่ยวกับ Password แน่ๆ
ใช่ครับ เกี่ยวกับการเข้ารหัส Password ที่จะใช้ Login โดยส่งไปกับ Protocol SMB ครับ
ทีนี้ตรงนี้เนี่ย ผมเองยังไม่ได้ศึกษาลงไปลึกถึงขั้นอ่าน Source code (เพราะขี้เกียจครับ)
และผมปล้ำให้ใช้งานได้แล้ว เลยยิ่งขี้เกียจศึกษาเข้าไปใหญ่ แต่ผมเคยพบปัญหาดังนี้...
ถ้ากำหนดเป็น yes เนี่ย ผมเคยเจอกรณีที่ Windows เวอร์ชั่นไหนๆ ก็ Login ไม่ได้เลย
ผมคาดว่าน่าจะเป็นเพราะ Encrytion method ไม่เหมือนกันเลย (อันนี้ไม่ Configrm นะครับ เพราะยังขี้เกียจอยู่)
แต่พอกำหนดเป็น no แล้ว Windows XP ขึ้นไปจะสามารถส่ง Password แบบ Plain text ได้
ก็ทำให้สามารถ Login เข้าไป Access ที่แชร์ไว้ได้หมดโดยไม่ต้องไปทำอะไรกับ Windows เลย
แต่ว่า... ถ้าเป็น Windows Me และ 9x ... อ้อ รวมถึง 2000 ด้วย ก็จะเป็นต้องไปเพิ่ม Registry
ให้ EnablePlainTextPassword เป็น 1 (dword) เสียก่อน ถึงจะใช้ได้ เพราะปกติแล้ว
Windows Me, 9x และ 2000 จะ Encrypt ตลอดครับ
>> hosts allow = 192.168.1. 192.168.2. 127.
ตรงนี้หมายถึง ยินยอมให้เครื่อง Client ใดบ้างสามารถ Login กับ SAMBA ได้ไงครับ
เป็น Security อีกระดับหนึ่งที่ Windows ไม่มีครับ มันเป็นขั้นแรกก่อนการ Login เสียอีก
เช่น ถ้ากำหนด 192.168.1. เอาไว้ หมายความว่า เครื่องที่มี IP = 192.168.1.xxx
จะสามารถ Login เข้า SAMBA ได้หมด
ถ้าเป็น 127. ก็คือเครื่องที่มี IP = 127.xxx.xxx.xxx ก็ Login ได้หมด
แล้วเครื่องที่ไม่อยู่ในรายชื่อเหล่านี้ล่ะ SAMBA จะไม่ Response อะไรออกไปเลยไงครับ
จะมองไม่เห็นเลย เพราะจะไม่ตอบอะไรกลับไปเลย เหมือน Server ไม่มีตัวตนเลย
ที่ผมขอดูไฟล์ hosts ก็เพราะเหตุนี้ครับ เช่น Server ที่บ้านผม ผมจะกำหนดในไฟล์ hosts ไว้ตัวอย่างดังนี้
192.168.0.??? bedroom (เครื่องในห้องนอน)
192.168.0.??? parlour (เครื่องในห้องรับแขก)
192.168.0.??? lab1 (เครื่องในห้องทำงานตัวที่ 1)
192.168.0.??? lab2 (เครื่องในห้องทำงานตัวที่ 2)
192.168.0.??? l7300 (Notebook ของผม)
แล้วในไฟล์ smb.conf ของผมก็จะมี...
hosts allow = bedroom parlour lab1 lab2 l7300 192.168.0.41/43
หมายความว่า เครื่องแปลกปลอมอื่นๆ ที่ไม่มี IP ตามรายชื่อนี้ ไม่มีสิทธิมองเห็น Server ผมเลยด้วยซ้ำครับ อย่าว่าแต่ Login เลย
สังเกตุตอนท้ายไหมครับ ผมมี 192.168.0.41/43 ด้วย... นั่นคือ IP สำหรับ DHCP ครับ
คืองี้ครับ ผมตั้งให้ DHCP Server ที่ Router จ่าย IP ได้ 3 เบอร์เท่านั้นคือ 192.168.0.41 ถึง 43
เอาไว้เวลาผม Set เครื่องใหม่ๆ ทีแรกอาจยังไม่ได้กำหนด IP ตายตัว ก็จะได้รับ IP จาก DHCP มาใช้ชั่วคราวก่อน
นอกจากนั้นยังเอาไว้กรณี Notebook พี่น้องเพื่อนฝูงมาเสียบเข้า Network ที่บ้านผมจะได้มี IP ใช้ด้วย
ดังนั้น การที่ผมระบุใน hosts allow = 192.168.0.41/43 ก็หมายความ ให้ SAMBA บริการเครื่องที่มี IP ตั้งแต่
192.168.0.41 จนถึง 43 ด้วยนั่นเองครับ
ทำความเข้าใจให้ดีนะครับ ตรงนี้ เพราะถึงแม้จะกำหนด security = share ก็ตาม แต่ถ้า hosts allow ไม่ได้กำหนดให้ยอมเข้าถึง
ก็หมายความ เครื่องแปลกปลอมนั้นๆ จะไม่ได้รับการตอบสนองใดๆ จาก SAMBA เลย ตรงนี้เป็น Security ด่านแรกสุดเลยครับ
การทำตรงนี้ ทำให้พวก Virus ที่สำเนาตัวเองผ่าน SMB Protocol ของพี่ Windows หมดสิทธิกล้ำกลายเลยครับ
เพราะ Virus ทั้งหลายที่อยู่บน Windows (ยังมีเครื่องที่เป็น Windows อยู่บ้างในระบบผม) นั้น มักจะปลอมใน Header ของ
SMB Protocol ว่าตัวเองมาจาก IP อื่น (โดยมากจะเป็น 0.0.0.0) ซึ่งจะทำให้ SAMBA ไม่ตอบสนองเลย แต่เราก็จะรู้ได้ว่า
Virus ได้พยายามคัดลอกตัวเองมา โดยดูได้จากใน log ที่ SAMBA บันทึกไว้ให้ และมีทุกวันวันละ 40-50 ครั่ง ที่มันจาก Internet เลย
โดยเฉพาะมาจาก ISP เอง (มาจากเครื่องคอมพิวเตอร์ที่เป็น Windows ของพนักงานใน Network ของ ISP)
ซึ่งผมรู้จากการดู IP ที่มาว่ามาจากไหน และดูจาก netbios name (ชื่อเครื่อง) และเมื่อรู้ชื่อเครื่อง ก็มักจะเดาออกได้ง่าย
เพราะชื่อเครื่องมักจะกำหนดจากตำแหน่งพนักงานหรือชื่อแผนก (เมื่อก่อนผมเป็น Admin บริษัทเอกชน ผมก็ทำเช่นนี้... เรื่องธรรมชาติ)
นอกจากนี้ ยังมีสิ่งที่ต้องคำนึงถึงอีกอย่างคือ การกำหนดใน hosts allow เป็น IP โดยตรง หรือกำหนดเป็น host name เนี่ย มีความต่างกันด้วยนะครับ
เช่น....
ตอนแรก ผมเคยกำหนดในไฟล์ hosts ให้มี
192.168.0.41 dhcp1
192.168.0.42 dhcp2
192.168.0.43 dhcp3
แล้วใน smb.conf แทนที่ผมจะมี 192.168.0.41/43 ผมก็ใส่เป็น dhcp1 dhcp2 dhcp3 ด้วยหมายว่า จะยอมให้ 3 IP นี้สามารถใช้บริการ SAMBA ได้
แต่ผลว่าไม่เป็นเช่นครับ Notebook เพื่อนฝูงมาเสียบแล้ว ได้ IP จาก Router ไปถูกต้อง แต่ SAMBA ไม่ตอบสนองครับ
ผมไปตรวจดูใน log ผมพบว่า SAMBA ตรวจพบว่า netbios name (ชื่อเครื่อง) ของ Notebook ไม่ตรงตามที่เรากำหนดในไฟล์ hosts
ดังนั้นจึงไม่ตอบสนอง บางเครื่องไม่ได้กำหนดชื่อเอาไว้ ใน log ก็จะว่า Unresolve netbios name
ผมเลยพบว่า กรณีจะให้ SAMBA รองรับเครื่องที่ IP ไม่นิ่ง (Dynamic IP) ซึ่งก็คือเครื่องที่รับ IP จาก DHCP Server นั้น
จำเป็นต้องระบุเป็น IP ตรงตัวไปเลย และทำให้เข้าใจถึงระบบ Security ของ SAMBA มากขึ้นอีกว่า
ถ้าเราจะบุใน hosts ก่อนแล้ว SAMBA จะตรวจดูด้วยว่า เครื่องที่ร้องขอเข้ามานั้น นอกจาก IP จะต้องตรงตามไฟล์ hosts แล้ว
ชื่อเครื่องยังต้องตรงตามที่ระบุไว้ด้วย นี่ก็เป็นอีกด่านหนึ่งที่จะทำให้เกิดปัญหางุนงงกัน แล้วหาสาเหตุกันไม่ได้ ดูเหมือน Set กันถูกต้องหมดแล้ว ทำไมถึงใช้ไม่ได้
อย่างอื่นคุณเข้าใจได้ถูกต้องแล้วครับ
ทีนี้ หากยังติดขัดอีกให้ถามมานะครับ เพราะยังไม่หมดมุขครับ มันยังมีที่จะทำให้คุณติดปัญหาได้อีก
เช่น Firewall เป็นต้น และยังมีเรื่องงงง่ายๆ ของ File/Directory permission กับ SAMBA อีก
และยังมีเรื่อง Create mask กับ Directory mask อีก
สรุปว่า Security มันซับซ้อนกว่า Windows ครับ แต่ถ้าเข้าใจหมด กำหนดได้หมดแล้ว มันปลอดภัยกว่า Windows มากครับ
หาช่องโหว่ยากกว่ามากเลย (ผมยังหาไม่เจอ แต่ก็ยังหาอยู่ยามว่าง)
ถ้าทำตามหมดแล้ว ยังไม่ได้ ไม่ต้องแปลกใจนะครับ ไม่ต้องตกใจด้วย ถามมาต่อเลยครับ
แล้วผมจะขอดูอย่างอื่นที่เกี่ยวข้องอีก เพื่อหาที่มาของปัญหาให้ครับ
พอก่อนแล้ว... เมื่อยอีกแล้วครับ...


[quote:510b5d44c4]มีวิธีการอย่างไร ให้ Samba มอง User และ Password ไปที่ User Manger
ของ Linux ครับ.. หรือว่า Add New User ที่ User Manager ของ Linux
แล้วสามารถไปกำหนด ให้กับ User ของ Samba ด้วยเลย [/quote:510b5d44c4]
น่าจะต้องกำหนดใน global ของไฟล์ /etc/samba/smb.conf คือ
[code:1:510b5d44c4] unix password sync = no -> เปลี่ยนเป็น Yes[/code:1:510b5d44c4]

อ๊ะๆ... ไม่ควรนะครับ คุณ wd
เราไม่ควรกำหนด unix password sync = yes ครับ... เพราะอะไรน่ะหรือ...
ดูนะครับ
โดยปกติ SAMBA ก็ไม่แนะนำให้ทำเช่นนั้นอยู่แล้ว ดูจาก comment ที่เขา default มาจะเห็นดังนี้ครับ...
# The following are needed to allow password changing from Windows to
# update the Linux system password also.
# NOTE: Use these with 'encrypt passwords' and 'smb passwd file' above.
# NOTE2: You do NOT need these to allow workstations to change only
# the encrypted SMB passwords. They allow the Unix password
# to be kept in sync with the SMB password.
unix password sync = No
passwd program = /usr/bin/passwd %u
passwd chat = *New*password* %n\n *Retype*new*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*
จะเห็นได้ว่า เขาไม่แนะนำอยู่แล้ว
ตรงนี้ ถ้ากำหนดเป็น yes หมายถึงการ Synchronize password กับระบบครับ
คือการอนุญาตให้เปลี่ยน password ของ user ในระบบผ่าน Protocol SMB ได้
เมื่อกำหนดเป็น yes แล้ว SAMBA จะเรียกโปรแกรมตามที่เรากำหนดใน
passwd program = /usr/bin/passwd %u
ซึ่งก็คือโปรแกรม /usr/bin/passwd และส่ง Parameter เป็น username ที่จะเปลี่ยน password ก็คือ %u จะแทนที่ด้วยค่า username นั้นๆ
แล้วจะคอยสายอักขระจากโปรแกรม passwd จนกว่าจะมีสายอักขระตามที่กำหนดใน
passwd chat = *New*password* %n\n *Retype*new*password* %n\n
ออกมา ซึ่งก็คือรอจนมีคำว่า New password ออกมา แล้ว SAMBA ก็จะจัดการใส่ค่า password ใหม่เข้าไปเอง ซึ่งก็คือ %n แล้วตามด้วย line feed (เหมือนกดปุ่ม Enter) ซึ่งก็คือ \n
แล้วรอให้มีสายอักขระว่า Retype new password ออกมา ก็จะทำการส่ง password ใหม่พร้อม line feed
ให้เสร็จสรรพ แล้วรอตรวจสอบว่าการเปลี่ยน password เป็นไปโดยสมบูรณ์ด้วยการรอตรวจสายอักขระ
ว่า all authentication updated successfully ก็แปลว่าเปลี่ยน password สมบูรณ์
ซึ่ง... ตรงนี้ไม่ปลอดภัยโดยเฉพาะกับ User ที่ขาดความเข้าใจ
แต่มันเหมาะจะใช้ตอนไหนหรือครับ...
มันเหมาะจะใช้เช่นกรณีองค์กรใหญ่ๆ ที่ Admin ไม่ค่อยว่างเป็นต้น
เช่นมี User ใหม่ และ Admin อาจอนุโลมให้ User ตั้ง Password ของตัวเองได้ในครั้งแรก
จึงสร้าง User ให้โดยไม่กำหนด Password (แก้ไขในไฟล์ /etc/password)
หลังจากนั้น User รายนั้นจะสามารถ Access เข้า SAMBA โดยไม่ต้่องป้อน password
และเขาสามารถเปลี่ยน Password (ตั้ง Password) ได้เองในครั้งแรก
และหลังจากนั้น Admin ก็ไม่อนุญาตอีก ซึ่งกระทำได้โดยการเขียน Script
และไปแทนที่ใน passwd program =
ทำให้กำหนดได้ในครั้งแรกครั้งเดียว และ Admin ก็ไม่ต้องไปเทียววิ่งหา User ให้จัดแจงกำหนด Password ครับ
ดังนั้น ตรงนี้ ผมไม่แนะนำให้กำหนดเป็น yes ครับ


Posts: 5
Joined: 12-04-2005