Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Samba 伺服器設定檔 smb.conf 深度解析:全域參數、安全模式、共享定義與實務調校

編輯:Linux 教學

Samba 透過 /etc/samba/smb.conf 設定,修改後需 service smb restart 或 reload 生效。本文系統拆解 [global] 關鍵參數(工作群組、安全模式、日誌、Socket 優化、WINS、列印、字碼頁)、三種安全模式 (share/user/server/domain) 遷移步驟、共享區塊參數 (path, browseable, writable, valid users, create mask 等)、建立 Samba 使用者 (smbpasswd, mksmbpasswd.sh)、測試指令 (testparm, smbclient, smbstatus) 完整實務操作流程。

[global] 關鍵參數精選


workgroup = MYGROUP           # 工作群組名,建議與 Windows 一致
server string = Samba Server  # 網路上鄰居顯示備註
security = user               # 安全模式: share/user/server/domain
encrypt passwords = yes       # 必須啟用加密密碼 (現代 Windows 預期)
smb passwd file = /etc/samba/smbpasswd
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192  # 傳輸效能優化
log file = /var/log/samba/%m.log
max log size = 0              # 0=不限制, 單位 KB
wins support = yes            # 啟用 WINS 伺服器
dns proxy = no                # 不代理 DNS 查詢

四種安全模式遷移路徑

模式驗證方式適用場景關鍵設定
share無用戶驗證,僅共享密碼極簡單環境security = share, guest account
userSamba 內建用戶資料庫中小型獨立伺服器security = user, smbpasswd -a user
server委派給另一台 SMB 伺服器 (如 NT PDC)既有 NT 域環境security = server, password server = NT_PDC
domain加入 Windows 域,由 PDC 驗證企業域環境security = domain, net join

共享區塊常用參數


[homes]
    comment = Home Directories
    browseable = no
    writable = yes
    valid users = %S
    create mode = 0664
    directory mode = 0775

[sharedoc]
    path = /home/sharedoc
    public = no
    writable = yes
    valid users = mary, fred
    create mask = 0765

[pub]
    path = /home/pub
    public = yes
    writable = yes
    create mask = 0765

建立 Samba 用戶實務步驟 (user 模式)

  1. 建立系統帳號:useradd -s /sbin/nologin user1 → passwd user1
  2. 加入 Samba 資料庫:smbpasswd -a user1 (輸入 Samba 密碼)
  3. 或批次匯入:cat /etc/passwd | mksmbpasswd.sh > /etc/samba/smbpasswd → 再逐一 smbpasswd user1 設定密碼。
  4. 重啟服務:service smb restart

常用測試與維護指令


testparm                    # 語法檢查
testparm /etc/samba/smb.conf client_ip  # 模擬客戶端看可存取資源
smbclient -L localhost      # 列出本機共享
smbstatus                   # 顯示目前連線/鎖定/開啟檔案
service smb reload          # 熱重載設定
chkconfig --level 35 smb on # 開機自啟

Windows 端對應設定

  • C:\Windows\System32\drivers\etc\hosts 加入 Samba 伺服器 IP/主機名對應。
  • Linux /etc/hosts 加入 Windows 客戶端 IP/主機名。

掌握 smb.conf 核心邏輯,即可建立穩定、安全、高效能的跨平台檔案共享服務。

Copyright © Windows教程網 All Rights Reserved