1.安裝samb服務端和客戶端
yum install samba samba-client samba-swat
samba-swat 基於https協議的samba服務器web配置界面
2.啟動服務
[root@wls12c ~]$ /etc/init.d/smb start 啟動 SMB 服務: [確定] [root@wls12c ~]$ /etc/init.d/nmb start 啟動 NMB 服務: [確定]
其中nmb服務是讓通過主機名代替IP地址來訪問局域網里的主機。
3.設置開機自啟動
chkconfig --level 35 smb on
4.編輯配置文件
cd /etc/samba/ mv smb.conf smb.conf.org egrep -v '^#|^;|^#' smb.conf.org >smb.conf
看看過濾后的配置文件
[global] #全局參數。 workgroup = MYGROUP #工作組名稱。 server string = Samba Server Version %v #服務器介紹信息,參數%v為顯示SMB版本號。 log file = /var/log/samba/log.%m #定義日志文件存放位置與名稱,參數%m為來訪的主機名。 max log size = 50 #定義日志文件最大容量為50Kb。 security = user #安全驗證的方式,總共有4種。 #share:來訪主機無需驗證口令,更加方便,但安全性很差。 #user:需由SMB服務驗證來訪主機提供的口令后才可建立訪問,更加的安全。 #server:使用獨立的遠程主機驗證來訪主機提供的口令(集中管理帳號)。 #domain:使用PDC來完成驗證 passdb backend = tdbsam #定義用戶后台的類型,共有3種。 #smbpasswd:使用SMB服務的smbpasswd命令給系統用戶設置SMB密碼。 #tdbsam:創建數據庫文件並使用pdbedit建立SMB獨立的用戶。 #ldapsam:基於LDAP服務進行帳戶驗證。 load printers = yes #設置是否當Samba服務啟動時共享打印機設備。 cups options = raw #打印機的選項 [homes] #共享參數 comment = Home Directories #描述信息 browseable = no #指定共享是否在“網上鄰居”中可見。 writable = yes #定義是否可寫入操作,與"read only"相反。 [printers] #打印機共享參數 comment = All Printers path = /var/spool/samba #共享文件的實際路徑(重要)。 browseable = no guest ok = no #是否所有人可見,等同於"public"參數。 writable = no printable = yes
案列1:創建一個共享文件目錄,無需密碼即可訪問
1.編輯配置文件
vim smb.conf
[global] workgroup = WORKGROUP server string = Samba Server Version %v netbios name = wls12c #定義windows中顯示出來的計算機名稱 log file = /var/log/samba/log.%m # max 50KB per log file, then rotate max log size = 50 security = share [public] comment = Public Stuff #對共享目錄的說明文件,自己可以定義說明信息 path = /share browseable = yes public = yes writable = yes
2.創建共享目錄
mkdir /share chmod 777 /share
3.測試配置的smb.conf是否正確
[root@wls12c samba]$ testparm Load smb config files from /etc/samba/smb.conf rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) Processing section "[public]" WARNING: The security=share option is deprecated Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions [global] server string = Samba Server Version %v security = SHARE log file = /var/log/samba/log.%m max log size = 50 client signing = required idmap config * : backend = tdb [public] comment = share all path = /share read only = No guest ok = Yes
4.重啟smb服務
/etc/init.d/smb restart
在window訪問:

Linux下訪問:

案列2:公司現有多個部門,因工作需要,將UAT部的資料存放在samba服務器的/UAT 目錄中集中管理。
創建共享目錄
mkdir /uat chmod 777 /uat
添加UAT部和用戶
[root@wls12c ~]$ groupadd uat [root@wls12c ~]$ useradd -g uat keven [root@wls12c ~]$ useradd -g uat tom
將剛才創建的用戶加入samba中

修改配置文件
[global] workgroup = WORKGROUP server string = Samba Server Version %v netbios name = wls12c log file = /var/log/samba/log.%m # max 50KB per log file, then rotate max log size = 50 security = user passdb backend = tdbsam load printers = yes cups options = raw [share] comment = share for users path = /uat browseable = yes public = no writable = yes
valid users = @uat
訪問

Linux訪問共享文件
訪問服務端
smbclient //192.168.0.90/share -U samba #匿名訪問可以省略掉-U
掛載和卸載服務端共享目錄
mount -t cifs //192.168.0.90/share /mnt -o username=samba,password=samba
umount //192.168.0.90/share
參考:http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html
