安装samba服务
yum install samba
管理samba服务
查看SMB服务状态:systemctl status smb
启动SMB服务:systemctl start smb
重启SMB服务:systemctl restart smb
设置开机自启:systemctl enable smb
关闭SMB服务:systemctl stop smb
配置Samba服务
添加一个系统用户user1
useradd user1
passwd user1
添加一个smb用户
smbpasswd -a user1 # 设置密码,创建user1用户
smbpasswd -e user1 # 激活该用户
创建一个共享文件 /share/public
mkdir -p /share/public
将这个文件的权限交给user1,因为你是用root创建的,这个文件的所有者是root
chown user1 /share
配置文件:/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
workgroup = Workgroup
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
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[test]
comment = share #描述信息
path = /share #共享文件的路径
public = no #是否允许匿名访问
writable = yes #是否有写权限
valid users = user1 #允许访问的用户
设置完后保存退出
重启一下
systemctl restart smb
访问共享文件夹
\\192.168.11.161 #\\ + ip
踩的坑:
为什么我没写匿名用户登陆呢:
我在配置:security = share后重启总是报错,加上这一句重启报错,改为security=user就不报错,我很郁闷,直到我看到了网上的一篇文章:http://www.3qphp.com/linux/centos/2796.html
折腾了好几个小时,我还以为虚拟机坏了,还恢复了快照重新弄的。知道真相的我哭晕在厕所。。。