如何在 CentOS 上配置 Samba
本文將指導您在 CentOS 6.x 上配置 Samba 伺服器,包括匿名和安全 Samba 資料夾。Samba 是一個開源/免費軟體套件,它為 SMB/CIFS 客戶端提供對檔案服務的無縫訪問。與其他工具不同,Samba SMB/CIFS 實現允許在 Linux 伺服器和 Windows 客戶端之間共享資料夾。
安裝
使用以下命令安裝 Samba 軟體包:
# yum -y install samba # mkdir /samba
授予 Samba 伺服器資料夾許可權
# chmod -R 0755 /samba/anonymous/
您需要修改 /etc/samba/smb.conf 檔案中的 smb.conf 檔案。
出於安全原因,我將原始檔案的備份儲存在 /etc/samba/smb.conf 中。
# cp /etc/samba.smb.conf /etc/samba.smb.conf.old
為了避免混淆,我將刪除配置檔案並使用以下命令建立一個新檔案。
# rm -rf /etc/samba.smb.conf # vi /etc/samba/smb.conf
配置檔案設定
#======================= Global Settings ===================================== [global] workgroup = WORKGROUP security = share map to guest = bad user #============================ Share Definitions ============================== [MyShare] path = /samba/anonymous/ browsable =yes writable = yes guest ok = yes read only = yes
啟動 Samba 伺服器服務
# service smb restart
從 Windows 訪問共享
現在您可以從 Windows 計算機透過 \IP-ADDRES 訪問共享,方法是:**開始** -> **執行**。(例如:\192.168.2.225)
保護 Samba 共享
由於我們共享的檔案沒有任何安全性,因此可能會丟失您的寶貴資料,為了安全起見,請執行以下設定。
# groupadd smbgrp # useradd user1 -G sambagrp # smbpasswd -a user1
Output: New SMB password:<--yoursambapassword Retype new SMB password:<--yoursambapassword
現在在 /samba 資料夾中建立一個名為 **secured** 的資料夾,並授予如下許可權:
# mkdir -p /samba/secure # cd /samba # chmod -R 0777 /samba/secure/
再次編輯配置檔案:
# vi /etc/samba/smb.conf [...] [secured] path = /samba/secure valid users = @smbgrp guest ok = no writable = yes browsable = yes
# service smb restart
此外,請檢查以下設定:
# testparm Output: Load smb config files from /etc/samba/smb.conf rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) Processing section "[Anonymous]" Processing section "[secured]" Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions <--ENTER
使用匿名和安全兩種方式編輯配置檔案,以檢視共享的差異。
# vi /etc/samba/smb.conf Configuration file settings:
#======================= Global Settings ===================================== [global] netbios name = CENTOS server string = Samba Server %v map to guest = Bad User dns proxy = No idmap config * : ackbend = tdb #============================ Share Definitions ============================== [Anonymous] path = /samba read only = No guest ok = Yes [secured] path = /samba/secure valid users = @smbgrp guest ok = no writable = yes browsable = yes
現在您可以從 Windows 計算機透過 \IP-ADDRES 訪問共享,方法是:**開始** -> **執行**。(例如:\192.168.2.225)
這將要求您輸入使用者名稱和密碼,請輸入使用者名稱和密碼(例如:user1 及 user1 的密碼),現在您可以使用憑據訪問安全資料夾。
**結論** - 配置和成功設定後,您現在可以訪問 Linux 伺服器上的 Windows 共享(或)NTFS 共享,以便在 Windows 和 Linux 計算機之間提供或共享資料,無論是否使用匿名訪問,並且您可以為資料夾提供個人訪問或組訪問許可權。