samba 檔案共享
阿新 • • 發佈:2019-01-13
samba 檔案共享
在說 samba 之前,先放一條 cmd 命令在上面,相信會用得到
開啟cmd視窗執行命令
斷開所有連線
C:\Users>net use * /del /y
注意:
1. linux 中的使用者與 samba 中的使用者並沒有什麼關係,但 samba 中的使用者必須是 linux 系統中已有的使用者
2. windows 在連線 samba 時,同時只能連線一臺 samba 伺服器中的一條線路,但可以同時連線多臺 samba 伺服器,這個並不是 samba 的問題,而是 windows 本身的因素造成的
前情提要:
由於本部門為了保證自身資料不被洩露,決定不使用雲平臺的程式,要部署一臺備份共享伺服器,實現資料安全及資料共享
部門分為兩塊:運維和測試(測試隸屬於運維管轄)
要求:
1.運維及測試成員只能對自己的目錄有讀寫許可權,最終權在老大
2.建立一個集體共享目錄,所有人都有此目錄的許可權
3.限制 ip ,避免賬號密碼的洩露
一:安裝 server 端
# yum search samba #查詢smb檔案共享服務所需軟體 # yum install samba-client.x86_64 samba-common.x86_64 samba.x86_64 -y (samba-swat.x86_64 可配置網頁版) # systemctl start smb #啟動 smb # systemctl enable smb #開機自啟 # systemctl stop firewalld #關閉防火牆 # systemctl disable firewalld #防火牆開機禁啟 # netstat -antlupe | grep smb #檢視埠
不關閉防火牆時:
iptables -I RH-Firewall-1-INPUT 5 -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT iptables -I RH-Firewall-1-INPUT 5 -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT iptables -I RH-Firewall-1-INPUT 5 -p udp -m udp --dport 137 -j ACCEPT iptables -I RH-Firewall-1-INPUT 5 -p udp -m udp --dport 138-j ACCEPT iptables-save service iptables restart
二:建立每個部門的使用者組
# groupadd ceshi
# groupadd yunwei
三:先建立系統使用者,並加入自己的使用者組
# useradd -g ceshi -s /sbin/nologin cs
# useradd -g ceshi -s /sbin/nologin cs2
# useradd -g yunwei -s /sbin/nologin yw
# useradd -g yunwei -s /sbin/nologin yw2
# useradd -g yunwei -s /sbin/nologin admin
四:新增使用者:
# id ysg #檢視是否有 ysg 系統使用者。
# smbpasswd -a ysg #新增 ysg 系統使用者到 smb 服務使用者
# pdbedit -L #檢視 smb 服務允許使用者
# pdbedit -x ysg #刪除 ysg 使用者
系統中沒有 ysg 使用者時:
# id ysg #無 ysg 使用者
id: ysg: no such user
# smbpasswd -a ysg
New SMB password:
Retype new SMB password:
Failed to add entry for user ysg. #新增不成功
# useradd ysg #建立westos使用者
# smbpasswd -a ysg
New SMB password:
Retype new SMB password:
Added user ysg. #此時新增成功
六:建立目錄
# mkdir -p /etc/samba/ ceshi yunwei
# mkdir -p /etc/samba/ ceshi ceshi
# mkdir -p /etc/samba/ ceshi share
七:更改配置檔案,實現許可權的分配,限制 ip 登入白名單
# hosts allow = the hosts allowed to connect. This option can also be used on a
# per-share basis.
#
# hosts deny = the hosts not allowed to connect. This option can also be used on
# a per-share basis.
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
hosts allow = 192.168.80.110 192.168.80.111
#[homes]
# comment = Home Directories
# valid users = %S, %D%w%S
# browseable = No
# read only = No
# inherit acls = Yes
[共享目錄]
comment = this is share
path = /etc/samba/share
writable = yes
admin users = @yunwei,@ceshi
valid users = @yunwei,@ceshi
create mask = 777
directory mask = 777
[運維]
comment = this is yunwei
path = /etc/samba/yunwei
writable = yes
admin users = admin,@yunwei
valid users = admin,@yunwei
create mask = 664
directory mask = 775
[測試]
comment = this is ceshi
path = /etc/samba/ceshi
writable = yes
admin users = admin,@ceshi
valid users = admin,@ceshi
create mask = 664
directory mask = 775
實現上面的 下面就不必配置了
配置 selinux:
# getsebool -a | grep smb
smbd_anon_write --> off
# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off
# setsebool -P samba_enable_home_dirs on
# setsebool -Psamba_export_all_rw on