在server上配置samba服务
samba服务器必须是STAFF工作组的一个成员
共享/common目录,共享名为common
只有example.com域内的客户端可以访问common共享、
common必须是可以浏览的
用户natasha必须能够读取共享中的内容,如果需要的话,验证密码是:tangkai
//在server上配置samba服务
[root@zzg ~]# yum -y install samb*
//samba服务器必须是STAFF工作组的一个成员
[root@zzg ~]# vim /etc/samba/smb.conf
workgroup = STAFF
security = user
passdb backend = tdbsam
//共享/common目录,赋予权限
[root@zzg ~]# mkdir /common
[root@zzg ~]# setfacl -m u:natasha:r-x /common
//用户natasha必须能够读取共享中的内容,如果需要的话,验证密码是:tangkai ,共享名为common
[root@zzg ~]# smbpasswd -a natasha
New SMB password:
Retype new SMB password:
Added user natasha.
[root@zzg ~]# tail -5 /etc/samba/smb.conf
[common]
path = /common
browseable = yes
write list = natasha
writable = no
//只有example.com域内的客户端可以访问common共享
[root@zzg ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=192.168.26.0/24 service name=samba accept' --permanent
success
[root@zzg ~]# firewall-cmd --add-rich-rule 'rule family=ipv4 source address=192.168.26.0/24 service name=samba-client accept' --permanent
success
[root@zzg ~]# firewall-cmd --reload
success
[root@zzg ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens32
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="192.168.220.0/24" service name="samba" accept
rule family="ipv4" source address="192.168.220.0/24" service name="samba-client" accept
//允许用户访问,开启家目录
[root@zzg ~]# 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_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off
[root@zzg ~]# setsebool samba_enable_home_dirs on
[root@zzg ~]# chcon -Rt samba_share_t /common/
//客户端安装samba-client
[root@zzg ~]# yum -y install samba-client
[root@zzg ~]# smbclient -L 192.168.220.40 -U natasha
Enter SAMBA\natasha's password:
Domain=[ZZG] OS=[Windows 6.1] Server=[Samba 4.6.2]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
common Disk
IPC$ IPC IPC Service (Samba 4.6.2)
natasha Disk Home Directories
Domain=[ZZG] OS=[Windows 6.1] Server=[Samba 4.6.2]
Server Comment
--------- -------
Workgroup Master
--------- -------
STAFF
//验证
[root@zzg ~]# mount -t cifs -o username=natasha,password=tangkai //192.168.220.40/
common /media
[root@zzg ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 1.1G 17G 6% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.6M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 497M 136M 362M 28% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/sr0 3.8G 3.8G 0 100% /mnt
//192.168.220.40/common 18G 1.1G 17G 7% /media
[root@zzg ~]# cd /media/
[root@zzg media]# ls
多用户samba挂载
在server上通过samba共享目录/storage
共享名为share
共享目录只能被example.com域内的客户端使用
共享目录share必须可以被浏览
用户sarah能以读的方式访问此共享,访问密码是tangkai
用户kitty能以读的方式访问此共享,访问密码是tangkai
此共享永久挂载在desktop上的/media/目录,并使用用户sarah进行认证,任何用户可临时通过kitty来获得读写权限
// 在server上通过samba共享目录/storage,赋予权限
[root@zzg ~]# mkdir /storage
[root@zzg ~]# setfacl -m u:kitty:rwx /storage/
[root@zzg ~]# setfacl -m u:sarah:r-x /storage/
//用户sarah能以读的方式访问此共享,访问密码是tangkai,用户kitty能以读的方式访问此共享,访问密码是tangkai
[root@zzg ~]# useradd kitty
[root@zzg ~]# useradd sarah
[root@zzg ~]# smbpasswd -a kitty
New SMB password:
Retype new SMB password:
Added user kitty.
[root@zzg ~]# smbpasswd -a sarah
New SMB password:
Retype new SMB password:
Mismatch - password unchanged.
Unable to get new password.
//共享目录share必须可以被浏览
[root@zzg ~]# vim /etc/samba/smb.conf
[root@zzg ~]# tail -6 /etc/samba/smb.conf
[share]
path = /storage
browseable = yes
valid users = kitty,sarah
writable = no
write list = kitty
//开启家目录
[root@zzg ~]# chcon -Rt samba_share_t /storage/
//重启服务
[root@zzg ~]# systemctl restart smb nmb
//客户端
[root@zzg ~]# smbclient -L 192.168.220.40 -U sarah
Enter SAMBA\sarah's password:
Domain=[ZZG] OS=[Windows 6.1] Server=[Samba 4.6.2]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
common Disk
share Disk
IPC$ IPC IPC Service (Samba 4.6.2)
sarah Disk Home Directories
Domain=[ZZG] OS=[Windows 6.1] Server=[Samba 4.6.2]
Server Comment
--------- -------
Workgroup Master
--------- -------
STAFF
//此共享永久挂载在desktop上的/media/dev目录,并使用用户sarah进行认证,任何用户可临时通过kitty来获得读写权限
[root@zzg ~]# vim /etc/fstab
//192.168.220.40/share /media cifs multiuser,username=sarah,password=tangkai,sec=ntlmssp 0 0
[root@zzg ~]# mount -a
[root@zzg ~]# yum -y install cifs-utils
[root@zzg ~]# su - zzg(只能在普通用户上操作)
[zzg@zzg ~]$ cifscreds add -u kitty 192.168.220.40
Password:
[zzg@zzg ~]$ cd /media (此时已经切换到kitty用户)
//验证
(客户端)
[zzg@zzg media]$ touch aa
(服务端)
[root@zzg ~]# ll /storage/
total 0
-rw-r--r--. 1 kitty kitty 0 Jan 15 06:38 aa