step 1 安装 yum -y install samba
step 2 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
重启网络
step 3 关闭 SELINUX (安全机制)
vim /etc/selinux/config
SELINUX=disabled
step 4 创建共享文件
mkdir /home/zxc/share
step 5 给要共享的文件权限(不给的话,不能写文件)
chown zxc:zxc share
step 6 添加共享文件
//建议使用下面得注意事项中示例
vi /etc/samba/smb.conf
#后面Windows添加映射磁盘刻就是\\xxx.xxx.xxx.xxx\shares,直接在默认文件后面加下面内容 #就可以
[shares]
comment = This is Alun's folder!
#不要指向没有权限的路径(用户名要一致,和系统用户(比如root用户(这个没试过),自己建的user用户(这里用户是zxc))直接同一个就行,不用新建)
path = /home/zxc/share
browseable = yes
writable = yes
valid users=zxc
step 7 将用户加入samba中
systemctl restart smb.service
systemctl restart nmb.service
smbpasswd -a zxc
step 8 加入开机自启动
systemctl enable smb
systemctl enable nmb
step 9 重启服务
reboot 重启虚拟机,前面的关闭selinux,需要重启才能生效
systemctl restart smb.service
systemctl restart nmb.service
step10 windows下链接
映射磁盘驱动器
映射完成后尝试创建文件,不能创建,可能时Linux上创建得文件夹权限有问题
注意事项:
主机和虚拟机相互之间可以ping通,最好使用桥接模式,在同一网段
配置文件举例
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
map to guest = Bad User
[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
[AlunFiles]
comment = This is Alun's folder!
path = /mnt/shares
public = yes
writable = yes
[shares]
comment = This is Alun's folder!
path = /home/zxc/share
browseable = yes
writable = yes
valid users=zxc //不能直接复制,这里容易开头复制成空格,应该位tab键,添加最后一个[shares]中的就可以