cifs
一. 安装部署samba
cifs文件系统共享
server:
yum install -y samba samba-common samba-client
systemctl start smb
ss -antlupe | grep smb
firewall-cmd --permanent --add-service=samba
firewall-cmd --reload
client:
yum install -y samba-client
测试:
二. 部署配置
vim /etc/samba/smb.conf #修改workgroup = SKY
systemctl restart smb.service
测试:
三. 黑白名单
1. 黑名单
vim /etc/samba/smb.conf #hosts deny = 172.25.254.175 不允许175主机访问
systemctl restart smb.service
测试:
2. 白名单
vim /etc/samba/smb.conf #hosts allow = 172.25.254.175 只允许175主机访问
systemctl restart smb.service
测试:
四. 配置共享目录
vim /etc/samba/smb.conf
[linux] #指定访问位置
comment = DATA directory
path = /westos #共享目录
systemctl restart smb.service
测试:
smbclient -L //172.25.254.170/linux
pdbedit -L #查看samba用户
smbpasswd -a #添加samba用户
smbpasswd -x #删除samba用户
setsebool -P samba_enable_home_dirs on
测试:
smbclient //172.25.254.170/linux -U student
semanage fcontext -a -t samba_share_t '/westos(/.*)?'
restorecon -RvvF /westos/
测试:
vim /etc/samba/smb.conf
tail -n 7 /etc/samba/smb.conf
[linux]
comment = DATA directory
path = /westos
writable = yes #可写
browseable = no #不隐藏目录
write list = student #可写用户列表,+student表示可写组为student
valid users = student # 可登陆用户,@student表示可登陆组为student
systemctl restart smb.service
测试:
mount //172.25.254.170/linux /mnt/ -o username=student,password=student
vim /etc/samba/smb.conf
tail -n 7 /etc/samba/smb.conf
[linux]
comment = DATA directory
path = /westos
writable = yes
browseable = no
; write list = student
; valid users = student
admin users = westos #以超级用户身份登陆,只表身份,不表功能
systemctl restart smb.service
测试:
mount //172.25.254.170/linux /mnt/ -o username=westos,password=westos
五. 匿名用户登陆设置
vim /etc/samba/smb.conf #125行map to guest = bad user
tail -n 9 /etc/samba/smb.conf
[linux]
comment = DATA directory
path = /westos
writable = yes
browseable = no
; write list = student
; valid users = student
admin users = westos
guest ok = yes
systemctl restart smb.service
测试:
mount -o username=guest,password="" //172.25.254.170/linux /mnt/
永久挂载---client
vim /etc/fstab
//172.25.254.170/linux /mnt cifs defaults,username=guest,password="" 0 0
mount -a
六. 多用户挂载---client
yum install -y cifs-utils
vim /root/smbfile
chmod 600 /root/smbfile
mount -o credentials=/root/smbfile,sec=ntlmssp,multiuser //172.25.254.170/linux /mnt/ #sec=ntlmssp表示认证方式,利用/root/smbfile文件认证;multiuser表示所用户登陆
cifscreds add -u student 172.25.254.170
注:多用户登陆可以提高文件的安全性,此过程中需要服务端两个samba用户及密码,在只登陆一次的过程中,通过用户转换为客户端sky用户,在不能提供另外一个samba用户及密码的情况下,sky用户没有权限查看已经共享的文件,增加文件信息的安全性