samba服務器的搭建
修改防火墻設定
firewall-cmd --permanent --add-service=samba //設定防火墻
firewall-cmd --reload //重新加載防火墻
安裝samba服務并啟動samba服務
yum install -y samba samba-client //安裝服務
systemctl start smb.service nmb.service //啟動服務
建立共享目錄
mkdir /home/company
創建訪問賬號
useradd -s /sbin/nologin xzusr
smbpasswd -a xzusr
選項說明:
-a 添加 smb 帳號;
-x 洗掉 smb 帳號;
-d 禁用 smb 帳號;
-e 啟用 smb 帳號
修改組態檔
修改組態檔:/etc/samba/smb.conf
[company] //共享名稱為 company
comment = company share//共享注釋
path = /home/company //指定共享路徑
browseable = yes //所有人可見
guest ok = no //拒絕匿名訪問
writeable = yes //支持寫入資料
valid users=xzusr,gcusr,xsusr //允許訪問的用戶串列
write list=xzusr //允許寫入的用戶串列
修改組態檔以后,必須重啟服務(systemctl restart smb nmb)使更改生效
測驗組態檔
testparm 當組態檔的語法出錯時會給出提示,修改再次運行 testparm 測驗
測驗samba服務器
在 linux 客戶端訪問測驗:smbclient -U smbuser //xxx.xxx.xxx.xxx/company
查看服務器的共享檔案有哪些:smbclient -L xxx.xxx.xxx.xxx
查看 smbuser 用戶可以訪問的共享檔案:smbclient -L xxx.xxx.xxx.xxx -U smbuser
匿名共享
1)創建共享目錄:
[root@localhost home]# mkdir share
[root@localhost home]# echo 'hello,world!'>/home/share/hello.txt
2)修改組態檔
[root@localhost home]# vim /etc/samba/smb.conf
security=share
[share] 共享名
comment=Linux share 共享目錄的注釋、說明資訊
path=/home/share 共享目錄
public=yes 允許所有samba用戶訪問該共享目錄
writable = yes
printable = no
write list = +staff
3)修改后重啟samba服務
[root@localhost home]#service smb restart
4)在windows客戶端測驗訪問:
開始--運行--\\xxx.xxx.xxx.xxx
此時發現可以看到共享檔案,但無法查看其內容,這是由于samba服務器上的
selinux導致的,需要將selinux改為許可模式:
[root@localhost home]# setenforce 0
帶身份驗證的檔案共享
(1)創建samb用戶:
[root@localhost home]# useradd smbuser
[root@localhost home]# smbpasswd -a smbuser
New SMB password:
Retype new SMB password:
使用smbpasswd命令可以對samba用戶進行管理,主要選項有:
-h 顯示smbpasswd命令的幫助資訊
-a 添加指定的samba用戶
-d 禁用指定的samba用戶
-e 啟用指定的samba用戶
-x 洗掉指定的samba用戶
(2)修改組態檔
將global中的 security=share 改為:security=user
改完后需要重啟smb服務
[root@localhost home]#service smb restart
(3)訪問測驗
在windows客戶端:開始--運行--\\192.168.10.1
此時你會發現需要輸入用戶和密碼進行驗證,
如果利用smbuser用戶連接共享檔案后,你想用smbadmin用戶連接共享檔案時你會發現是直接連接的,這是因為windows訪問時會快取,用如下辦法可解決此辦法:
開始--運行--cmd--net use * /del--y
設定共享權限
所有用戶都可以寫入
(1)修改組態檔
[root@localhost home]# vim /etc/samba/smb.conf
[share]
comment=Linux share
path=/home/share
public=yes
writable=yes
(2)修改共享目錄的權限:
[root@localhost home]#chmod 777 /home/share
setfacl -m u:nobody:rwx /home/share 訪問控制串列ACL
setfacl -x
只有指定用戶可以寫入
[root@localhost home]# vim /etc/samba/smb.conf
[share]
comment=Linux share
path=/home/share
public=yes
write list=smbadmin
writable=yes表示所有用戶都有寫入權限
write list=smbadmin表示指定smbadmin用戶有寫入權限
如果要指定多個用戶有寫入權限,用戶之間用,號隔開:write list=smbadmin,smbuser
只有指定用戶可以訪問
[root@localhost home]# vim /etc/samba/smb.conf
[share]
comment=Linux share
path=/home/share
valid users=smbuser,smbadmin
write list=smbadmin
允許/拒絕指定用戶的訪問
只允許在IP地址為x.x.x.x的客戶端上訪問teach共享目錄
[tech]
comment=technet
path=/home/technet
writable=yes
hosts allow=x.x.x.x
允許地址段x.x.x.x/xx內的用戶訪問tech共享目錄,IP地址為x.x.x.x的計算機除外
[tech]
Comment=technet
path=/home/technet
writable=yes
hosts allow=x.x.x.x EXCEPT x.x.x.x
teach(/home/tech),只有tech組的成員可以訪問和寫入權限
[tech]
Comment=technet
path=/home/technet
valid users=@tech
write list=@tech
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/153756.html
標籤:Linux
