一、搭建环境:
CentOS7.5 防火墙关闭状态
二、安装samba和介绍
1、samba安装
yum -y install samba
2、samba登录验证模式,即samba的安全级别
验证模式 | 介绍 | 备注 |
share | 匿名验证模式 | |
user(默认) | 本地用户验证模式 | tdbsam该方式是使用一个数据库文件来验证,数据库文件叫passdb.tab,可以通过pdbedit-a将系统用户转化成samba用户。 |
别名 | 虚拟用户验证方式 |
3、user模式的相关命令
pdbedit -a username #新建samba用户
pdbedit -x username #删除samba用户
pdbedit -L 列出samba用户的列表,即读取passdb.tdb数据库文件
4、虚拟用户模式
暂时省略,待写
三、新建用户
useradd -s /sbin/nologin hufeng #新建用户hufeng,但是不能让此用户登陆系统
pdbedit -a hufeng #设置samba用户密码
如果你先前已经新建了用户,可以在这里vim /etc/passwd 更改是否能登入系统和定义家目录。
pokes:x:1000:1000:pokes:/home/pokes:/bin/bash
yanyu:x:1001:1001::/home/yanyu:/sbin/nologin
hufeng:x:1002:1002::/home/hufeng:/sbin/nologin
/bin/bash 是允许登录系统 /sbin/nologin 是不允许登入系统
四、配置文件修改
vim /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA #工作组或者域
security = user #用户访问的验证方式
passdb backend = tdbsam #密码验证方式
printing = cups
printcap name = cups
load printers = yes #启动时是否共享打印机
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S #只允许用户访问各自的home目录,用户间不能互访
browseable = No
read only = No
inherit acls = Yes
writable = no #新增此项,不给写入权限
[shuju]
comment = hufeng #文件夹描述
path = /home/data/ftp/hufeng #共享目录
browseable = yes #让他可以看到
writable = no #不给写入权限
home是默认共享的家目录,我们自定义了一个shuju 目录,现在我们打开共享的话,会看到两个文件夹: 家目录+shuju
五、自定义共享文件夹
但是我们只想用户使用shuju文件夹,那我们直接删除homes选项,让配置文件变成如下样子:
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA #工作组或者域
security = user #用户访问的验证方式
passdb backend = tdbsam #密码验证方式
printing = cups
printcap name = cups
load printers = yes #启动时是否共享打印机
cups options = raw
[shuju]
comment = hufeng #文件夹描述
path = /home/data/ftp/hufeng #共享目录
browseable = yes #让他可以看到
writable = no #不给写入权限
配置目录权限
chmod -R 777 /home/data/ftp/hufeng
这样就可以实现自定义共享文件夹。
需要注意的是:一般采用这种共享方式建议不要给写入权限,员工都喜欢一键记住密码,这样的话要是中了勒索病毒,只要有写入权限就会一起感染。所以共享访问一般都不给写入权限,要想写入必须使用FTP写入。除非是数据不重要。
六、启动服务和开机自启动
systemctl start smb
systemctl enable smb