創作內容

0 GP

[Linux][CentOS 5.5] 6. SAMBA 服務設定、連線存取限制、資料夾分享與存取驗證

作者:game2002│2011-03-02 22:28:48│巴幣:0│人氣:10592
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 samba
Loaded 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 smbuser1
Changing 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 smbuser2
Changing 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  smbuser1
New SMB password:
Retype new SMB password:
[root@station7 ~]# smbpasswd -a  smbuser2
New 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 = @wheel


5. 重新啟動 samba 服務
[root@station7 ~]# /etc/init.d/smb restart
正在停止 SMB 服務:                                         [失敗]
正在停止 NMB 服務:                                         [失敗]
正在啟動 SMB 服務:                                         [  確定  ]
正在啟動 NMB 服務:                                         [  確定  ]


7. 驗證本地端是否可連線
[root@station7 ~]# smbclient //localhost/myshare -U smbuser1%linux

Domain=[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: \> exit


samba 連線時,如果連線失敗,請輸入 tail  /var/log/message 來觀看錯誤訊息,
一般來說會有2種修正方式:

method 1:修正分享目錄的權限
[root@station7 ~]# ls / -lZ | grep storage
drwxr-xr-x  root root root:object_r:default_t          storage
[root@station7 ~]# chcon -R -t samba_share_t /storage
[root@station7 ~]# ls / -lZ | grep storage
drwxr-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 samba
samba_enable_home_dirs --> on


8. 驗證
[root@station7 ~]# smbclient //localhost/myshare -U smbuser1%linux
Domain=[STATION3] OS=[Unix] Server=[Samba 3.0.33-3.29.el5_5.1]
smb: \> exit

[root@station7 ~]# smbclient //localhost/myshare -U smbuser2%linux
Domain=[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.conf

hosts 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:              [  確定  ]

引用網址:https://home.gamer.com.tw/TrackBack.php?sn=1247041
All rights reserved. 版權所有,保留一切權利

相關創作

同標籤作品搜尋:linux|fedora|samba|Linux|Fedora|CentOS

留言共 0 篇留言

我要留言提醒:您尚未登入,請先登入再留言

喜歡★gameculb2002 可決定是否刪除您的留言,請勿發表違反站規文字。

前一篇:[Linux][Cent... 後一篇:[Linux][Cent...

追蹤私訊切換新版閱覽

作品資料夾

aaa1357932大家
各位有空可以來我家看看畫作或聽聽我的全創作專輯!看更多我要大聲說昨天07:22


face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】