前言:为了使Windows用户以及Linux用户能够互相访问彼此的资源,实现不同操作系统的文件和打印共享,Linux提供了一套资源共享的软件——Samba服务器。
1. 安装sabma服务,(假设本台机器的IP为172.16.128.90)
yum install -y samba
2、启动samba服务
systemctl enable smb
systemctl enable nmb
systemctl start smb
systemctl start nmb
3. 新建普通用户
useradd docker
4、给docker用户设置密码,输入密码两次即可,(我这里密码也设置为docker)
smbpasswd -a docker
5、 创建需要共享的挂载目录,windows和linux共享
mkdir -p /smb/share
6、 给目录授权
chmod 777 /smb/share
7、挂载目录(根据个人情况也可以直接用系统盘,跳过此步骤;如果是想用一块新的硬盘,可以参照linux 初始化硬盘分区、挂载_almalinux 更改硬盘挂载点-CSDN博客,我这里是专门新增了一块硬盘来挂载)
mount -t xfs /dev/sdb1 /smb/share
8、配置samba文件,将共享目录添加到文件末尾并保存
vi /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
[share]
comment = share
path = /smb/share
public = yes
valid users = docker
security = share
guest ok = yes
writeable = yes
max connections = 65535
9、重启服务
systemctl restart smb
systemctl restart nmb
10、windows上UNC访问samba服务器,输入\\172.16.128.90\,输入账户密码(docker)连接服务测试,可以成功看到挂载的目录share,如果不能访问,请查看防火墙和selinux是否关闭。