Samba 是 Linux 與 Windows 共享檔案的標準方案。本文以 CentOS/RHEL 為例,示範從安裝套件、建立共享目錄、設定權限、建立 Samba 專用帳號、修改 smb.conf、啟動服務到 Windows 端測試存取的完整流程。
# 檢查是否已安裝
rpm -qa | grep samba
# 未安裝則安裝(含用戶端工具)
yum install samba samba-client samba-common -y


mkdir /home/fileshare
chmod 755 /home/fileshare



groupadd fileshare
useradd -s /sbin/nologin -g fileshare fileuser
smbpasswd -a fileuser # 設定 Samba 密碼

vim /etc/samba/smb.conf

[global]
workgroup = WORKGROUP
server string = Samba Server
security = user # 建議使用 user 模式,較 share 模式安全
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw

[sharefile]
path = /home/fileshare
public = no
writable = yes
valid users = @fileshare
create mask = 0664
directory mask = 0775

systemctl start smb nmb
systemctl enable smb nmb

firewall-cmd --permanent --add-service=samba
firewall-cmd --reload
在檔案總管輸入 \\Linux伺服器IP,輸入 fileuser 及剛設定的 Samba 密碼,即可讀寫共享資料夾。

setsebool -P samba_export_all_rw on)。nmb 服務運行(負責 NetBIOS 名稱解析),或直接用 IP 連線。smbpasswd 設定。