说明参考

https://www.lisenet.com/2016/samba-server-on-rhel-7/

安装

yum install -y samba samba-client

服务

systemctl enable smb nmb

加防火墙

1
2
firewall-cmd --permanent --add-service=samba
firewall-cmd --reload

安装工具

yum -y install policycoreutils-python.x86_64

创建共享目录

mkdir /srv/samba_group

配置权限

1
2
3
groupadd devops
chgrp devops /srv/samba_group
chmod 2775 /srv/samba_group

检查一下默认的SELinux

ls -dZ /srv/samba_*

将samba_share_t上下文类型应用于组共享

semanage fcontext -a -t samba_share_t "/srv/samba_group(/.*)?"

让samba可以创建新的主目录

setsebool -P samba_create_home_dirs = 1

要使用Samba共享NFS文件系统

setsebool -P samba_share_nfs = 1

写入权限

setsebool -P allow_smbd_anon_write=1

配置Samba

vim /etc/samba/smb.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[group]
comment = Group Share
path = /srv/samba_group/%U/
writable = yes
browseable = yes
printable = no
guest ok = no
write list = @devops
read list = @devops
valid users = @devops
create mask = 0660
directory mask = 0770

测试配置

testparm -s

输出Loaded services file OK
其它输出与配置文件一致则配置正确

查看目录

ls -dZ /srv/samba_group/

修改目录

c++hcon -t samba_share_t /srv/samba_group/

启动服务

systemctl start smb nmb

测试用户

smbclient //localhost/group -U dev1