安装:
yum install samba
apt install samba
Samba配置文件:
[global]
workgroup = MYGROUP
#netbios name = MYSERVER
server string = Samba Server
#interfaces = eth0
#hosts allow = 127. 192.168.168.
#unix charset = utf8
#dos charset = cp950
log file = /var/log/samba/log.%m
max log size = 50
log level = 3
#使用用户验证
security = user
#map未知用户使用smbguest访问,匿名时使用,windows10需启用匿名访问,否则提示网络错误
map to guest = Bad User
guest account = smbguest
load printers = no
#create mask = 666
#directory mask = 777
#密码存储类型
passdb backend = tdbsam
server min protocol = SMB2
client max protocol = SMB3
client min protocol = SMB2
allow insecure wide links = yes
[guest]
comment = guest file space
path = /data/temp
writable = yes
#不可视目录
browseable = no
#可匿名访问
guest ok = yes
#如需guest可访问但不可写,smbguest可写
#writable = no
#write list = smbguest
#跟踪软链接
follow symlinks = yes
wide links = yes
[demo]
comment = demo file space
path = /data/demo
writable = yes
browseable = no
guest ok = no
#定义smbguest可访问
valid users = smbguest
#强制新建的文件归属
#force user = root
force group = smbshare
create mask = 0660
#新建目录包含粘滞位权限,非目录所有者用户只能删除自己的文件,目录所有者不受此限制
directory mask = 1770
新建samba验证用户,新建的用户必须是系统用户
groupadd smbshare
#这里的-g如果用-G guest访问会出现权限问题
useradd -M -g smbshare -s /sbin/nologin smbguest
pdbedit -a smbguest
新建共享目录:
mkdir -p /data/demo
chown root:smbshare /data/demo
#2 任何用户新建文件及目录属于smbshare组,1仅创建者可删除文件,就算smbshare可写用户组其它用户
chmod 2775 /data/demo
mkdir -p /data/guest
chown root:smbshare /data/guest
chmod 2775 /data/guest