6. SAMBA 服務設定、連線存取限制、資料夾分享與存取驗證Subject:
- 請依下列敘述設定 samba 目錄
- 建立兩個使用者smbusers1 and smbuser2
- smbuser1 的主要 group 為 users ,次要 group 為 wheel ,密碼為 linux
- smbuser2 的主要 group 為 users ,密碼為 linux
- 分享 /storage directory
- share name must be myshare
- workgroup is centos
- 權限為 read-only, browseable
- only from 192.168.11.0/24 及127.0.0.1 的使用者能夠使用 samba 服務
- 只有 wheel 群組的成員可以使用 SAMBA server,其他不屬於 users 群組的都不能登入
- smbuser1 user 能夠 read the share, 並且登入需要認證,密碼是 linux
-----------------------------------------------------------------------------------------------------------------------------
solution:
1. 安裝samba 相關套件[root@station7 ~]# yum install sambaLoaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: ftp.isu.edu.tw
* base: ftp.isu.edu.tw
* extras: ftp.isu.edu.tw
* updates: ftp.isu.edu.tw
Setting up Install Process
Package samba-3.0.33-3.29.el5_5.1.i386 already installed and latest version
Nothing to do
2. 依題目要求建立使用者與密碼[root@station7 ~]# useradd smbuser1 -m -g users -G wheel[root@station7 ~]# useradd smbuser2 -m -g users [root@station7 ~]# passwd smbuser1Changing password for user smbuser1.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@station7 ~]# passwd smbuser2Changing password for user smbuser2.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
3. 將smbuser1 與smbuser2 使用者資訊加入samba 的驗證設定中[root@station7 ~]# smbpasswd -a smbuser1New SMB password:
Retype new SMB password:
[root@station7 ~]# smbpasswd -a smbuser2New SMB password:
Retype new SMB password:
4. 編輯 samba 設定檔 [root@station7 ~]# nano /etc/samba/smb.conf (
照下面設定)
workgroup = centos
hosts allow = 192.168.11.0/24 127.0.0.1
security = user
[myshare]
path = /storage
read only = yes
browseable = yes
valid users = @wheel5. 重新啟動 samba 服務[root@station7 ~]# /etc/init.d/smb restart正在停止 SMB 服務: [失敗]
正在停止 NMB 服務: [失敗]
正在啟動 SMB 服務: [ 確定 ]
正在啟動 NMB 服務: [ 確定 ]
7. 驗證本地端是否可連線[root@station7 ~]# smbclient //localhost/myshare -U smbuser1%linuxDomain=[STATION7] OS=[Unix] Server=[Samba 3.0.33-3.29.el5_5.1]
smb: \>
ls . D 0 Thu Mar 3 11:16:22 2011
.. D 0 Thu Mar 3 12:51:45 2011
38 0 Thu Mar 3 11:16:22 2011
49577 blocks of size 8192. 16549 blocks available
smb: \>
exitsamba 連線時,如果連線失敗,請輸入 tail /var/log/message 來觀看錯誤訊息,一般來說會有2種修正方式:method 1:修正分享目錄的權限
[root@station7 ~]# ls / -lZ | grep storagedrwxr-xr-x root root root:object_r:default_t storage
[root@station7 ~]# chcon -R -t samba_share_t /storage[root@station7 ~]# ls / -lZ | grep storagedrwxr-xr-x root root root:object_r:samba_share_t storage
method2:[root@station7 ~]# setsebool -P samba_enable_home_dirs=1[root@station7 ~]# getsebool -a | grep sambasamba_enable_home_dirs --> on
8. 驗證
[root@station7 ~]# smbclient //localhost/myshare -U smbuser1%linuxDomain=[STATION3] OS=[Unix] Server=[Samba 3.0.33-3.29.el5_5.1]
smb: \> exit
[root@station7 ~]# smbclient //localhost/myshare -U smbuser2%linuxDomain=[STATION3] OS=[Unix] Server=[Samba 3.0.33-3.29.el5_5.1]
tree connect failed: NT_STATUS_ACCESS_DENIED
9. 讓 samba 開機預設啟動 [root@station7 ~]# chkconfig smb on[root@station7 ~]# reboot
samba 的連線存取限制:
若:only from 192.168.11.0/24 及本機使用者能夠使用 samba 服務
[root@station7 ~]# nano /etc/samba/smb.confhosts allow = 127.0.0.1 192.168.11.0/24
[root@station7 ~]# /etc/init.d/smb restart
Shutting down SMB services: [ OK ]
Shutting down NMB services: [ OK ]
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
使用其他主機測試:
[gameculb2002@station2 ~]$ smbclient //192.168.11.3/myshare -U smbuser1%linux
Domain=[CENTOS] OS=[Unix] Server=[Samba 3.0.33-3.29.el5_5.1]
smb: \> ls
. D 0 Mon Mar 14 16:13:42 2011
.. D 0 Mon Mar 14 16:13:42 2011
49577 blocks of size 8192. 10390 blocks available
smb: \> exit
------------------------------------------------------------------------------------------------------------------------------
如果對於文字介面不熟悉,可以使用圖形化介面。
安裝圖形化介面的方法為:
[root@station3 /]# yum install system-config-samba
安裝完成之後,可以在 系統>管理>伺服器設定>samba 選擇圖形化界面。
既然可以圖形化設定samba 的 server 端,client 端也可以使用圖形化界面連線 server 端。
點擊 位置 > 連接到伺服器
服務類型選擇 Windows 分享,伺服器就填入 samba server 的IP ,
本範例的samba server 是 192.168.11.7 。
----------------------------------------------------------------------------------------------------------------------------
note1: 如果client 端無法連線,表示找不到通往主機host,
那有可能是被Server 端防火牆(iptables)擋住,解決方法如下:
連線到Server 端主機:
[root@station7 ~]# iptables -F
[root@station7 ~]# iptables -X
[root@station7 ~]# iptables -Z
[root@station7 ~]# iptables -Z -t nat
[root@station7 ~]# iptables -X -t nat
[root@station7 ~]# iptables -Z -t nat
[root@station7 ~]# iptables -F -t mangle
[root@station7 ~]# iptables -X -t mangle
[root@station7 ~]# iptables -Z -t mangle
(上面落落長就是將防火牆的規則清除乾淨!)
[root@station7 ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@station7 ~]# /etc/init.d/iptables save (記的要儲存防火牆的規則!)
正在儲存防火牆規則到 /etc/sysconfig/iptables: [ 確定 ]