Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Samba 與 Linux 檔案權限深度解析:目錄執行權限、建立權限與 writable 陷阱

編輯:Linux 系統常見問題解答

核心權限規則實驗結論

  1. 存取檔案需所有上層目錄具備 x (執行/進入) 權限:缺少任一層 x 即無法遍歷路徑。
  2. 建立檔案僅需該目錄具備 w (寫入) 權限:上層目錄 w 權限不影響建立操作。

Samba security = share 模式下的預設用戶

此模式下客戶端不提供用戶名,Samba 使用 nobody 帳號存取。需確保 nobody 對共享目錄樹具備上述權限。

經典陷阱:writable = no 覆蓋檔案系統權限

配置範例:

[home]
comment = Home Directories
path = /home
browseable = yes
writable = yes

[root]
comment = Root Directory
path = /
browseable = yes
writable = no

現象:即使 /home 目錄權限為 777,若客戶端連線到 [root] 共享 (路徑同為 /home 下的子目錄),Samba 的 writable = no 會直接拒絕寫入操作,檔案系統權限根本不會被檢查。

解決方案

  • 客戶端連線時指定正確的共享名稱 (上例應連 //server/home 而非 //server/root)
  • 或將 [root] 共享的 writable = yes (但需評估安全風險)
  • 最佳實務:共享層級權限 (writable/read only) 與檔案系統權限 (ACL/posix) 兩層都要正確,缺一不可。

權限除錯檢查清單

層級檢查項目指令
檔案系統目錄 x 權限完整性namei -l /path/to/share
檔案系統目錄 w 權限 (建立檔案)ls -ld /path/to/share
Samba 設定writable / read onlytestparm -s | grep -A5 'share name'
Samba 設定force user / force group檢查是否強制切換身份
SELinux/AppArmor安全模組阻擋ausearch -m avc -ts recent

補充:security = user 模式差異

若使用 security = user (預設),客戶端需提供帳號密碼,Samba 會對應系統用戶,權限判斷基於該系統用戶身份,而非 nobody。

Copyright © Windows教程網 All Rights Reserved