實驗拓撲:
linux client
-----rhel5.9(vmnet1)----------(vmnet1)
win7 client
實驗一:samba匿名共享
工作組為tarena
将目錄 /usr/src 共享給所有人
共享名設為 tools
允許所有人通路、無需密碼驗證
通路權限為隻讀
1、安裝軟體包
[root@localhost ~]# rpm -q samba-client samba samba-common
package samba-client is not installed
package samba is not installed
package samba-common is not installed
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# cp rhel-debuginfo.repo rhel-server.repo
[root@localhost yum.repos.d]# cat rhel-server.repo
[rhel-server]
name=red hat enterprise linux server
baseurl=file:///misc/cd/server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-redhat-release
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum -y install samba samba-client samba-common
2、修改主配置檔案
[root@localhost ~]# cd /etc/samba/
[root@localhost samba]# cp smb.conf smb.conf.bak
[root@localhost samba]# vim /etc/samba/smb.conf
74 workgroup = tarena
75 server string = win file ser
89 log file = /var/log/samba/%m.log
91 max log size = 50
101 security = share
221 load printers = no //屏蔽共享時看到的列印圖示
289 [tools]
290 comment = tools public
291 path = /usr/src
292 public = yes
293 read only = yes
3、啟動服務
[root@localhost ~]# testparm
[root@localhost ~]# service smb restart
[root@localhost ~]# chkconfig smb on
[root@localhost ~]# netstat -anptu | grep mbd
tcp 0 0 0.0.0.0:139 0.0.0.0:* listen 7008/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* listen 7008/smbd
udp 0 0 192.168.10.10:137 0.0.0.0:* 7011/nmbd
udp 0 0 0.0.0.0:137 0.0.0.0:* 7011/nmbd
udp 0 0 192.168.10.10:138 0.0.0.0:* 7011/nmbd
udp 0 0 0.0.0.0:138 0.0.0.0:* 7011/nmbd
4、用戶端測試:
linux:
[root@localhost ~]# yum -y install samba-client
[root@localhost ~]# smbclient -l 192.168.10.253
[root@localhost ~]# smbclient //192.168.10.253/tools
[root@localhost ~]# mkdir -p /data/smb
[root@localhost ~]# mount -t cifs //192.168.10.253/tools /data/smb/
[root@localhost ~]# grep smb /etc/fstab
//192.168.10.253/tools /data/smb cifs defaults 0 0
試驗二 samba使用者驗證
修改原有的 [tools] 匿名共享設定
不再允許所有人通路
隻允許nick讀取、tom寫入
拒絕其他使用者或匿名通路
上傳目錄的權限為755
上傳檔案的權限為644
1、建立相應賬戶與samba密碼
[root@localhost ~]# useradd nick
[root@localhost ~]# useradd tom
[root@localhost ~]# echo "redhat" | passwd --stdin nick
[root@localhost ~]# echo "redhat" | passwd --stdin tom
[root@localhost ~]# pdbedit -a nick
[root@localhost ~]# pdbedit -a tom
[root@localhost ~]# vim /etc/samba/smb.conf
101 security = user
292 public = no
293 valid users = nick,tom
294 write list = tom
295 read only = yes
296 directory mask = 0755
297 create mask = 0644
[root@localhost ~]# setfacl -m u:tom:rwx /usr/src/
4、用戶端測試
[root@localhost ~]# smbclient -u nick //192.168.10.10/tools
[root@localhost ~]# mount -o username=nick //192.168.10.10/tools /data/smb
試驗三 samba賬戶别名與通路位址控制
把普通帳戶nick設定别名為jim
設定隻允許192.168.10.20位址通路
1、修改samba使用者别名檔案
[root@localhost ~]# vim /etc/samba/smbusers
root = administrator admin
nobody = guest pcguest smbguest
nick = jim
76 username map = /etc/samba/smbusers
298 hosts allow = 192.168.10.5