Table of contents
Build a simple samba server in centos7 for testing to help understand the simple usage of samba services.
Background requirements:
- Set the public directory, everyone can access it, and the permission is
read-only; - Separate directories are established for the settlement center and the technical department, and only
the general manager of the company and employees of the corresponding department are allowed to visit;
Employees of the company cannot view the shared directory of non-department in "Network Neighborhood"
Environment preparation:
One centos7 host and one test machine
Intranet environment can also mount centos local source to install samba service
#因为是测试环境,所以直接关闭防火墙以及Selinux
[root@tttrark ~]# setenforce 0
[root@tttrark ~]# systemctl stop firewalld
#配置阿里云yum源
[root@tttrark ~]# rm -rf /etc/yum.repos.d/*
[root@tttrark ~]# curl -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo > /etc/yum.repos.d/Centos-7.repo
Create users and folders for sharing according to requirements
#创建管理员组
[root@tttrark ~]# groupadd managers
#创建结算中心组
[root@tttrark ~]# groupadd finace
#创建技术组
[root@tttrark ~]# groupadd technology
#创建对应文件夹以及文件
[root@tttrark ~]# mkdir -p /samba/public
[root@tttrark ~]# mkdir -p /samba/finace
[root@tttrark ~]# mkdir -p /samba/technology
[root@tttrark ~]# touch /samba/finace/finace.txt
[root@tttrark ~]# touch /samba/technology/technology.txt
[root@tttrark ~]# touch /samba/public/public.txt
#配置对应文件权限
[root@tttrark ~]# chmod -R 0777 /samba/public
[root@tttrark ~]# chmod -R 0770 /samba/finace
[root@tttrark ~]# chmod -R 0770 /samba/technology
[root@tttrark ~]# chown -R root:managers /samba/finace
[root@tttrark ~]# chmod -R 0770 /samba/finace
[root@tttrark ~]# chown -R root:managers /samba/technology
[root@tttrark ~]# chmod -R 0770 /samba/technology
[root@tttrark ~]#
#创建用户以及添加samba用户
[root@tttrark ~]# useradd finace1
[root@tttrark ~]# passwd finace1
[root@tttrark ~]# smbpasswd -a finace1
[root@tttrark ~]# usermod -G finace finace1
[root@tttrark ~]# useradd technology1
[root@tttrark ~]# smbpasswd -a technology1
[root@tttrark ~]# usermod -G technology technology
[root@tttrark ~]# useradd manager1 -g managers
[root@tttrark ~]# passwd manager1
[root@tttrark ~]# smbpasswd -a manager1
Modify the /etc/samba/smb.conf configuration file
#添加以下配置
[public]
path = /samba/public
browseable = yes
writable = no
guest ok = yes
[finace]
path = /samba/finace
valid users = @managers @finace
browseable = no
writable = yes
guest ok = no
[technology]
path = /samba/technology
valid users = @managers @technology
browseable = no
writable = yes
guest ok = no
#开启服务
systemctl start smb
systemctl enable smb
systemctl status smb
test
windows access shared files