说明:此程序在archlinux,opensuse,raspios上测试通过。
samba是一款开源的文件共享软件,经过简单配置就能够实现Linux系统与Windows系统之间的文件共享工作。
- 安装samba
yum install samba
- 修改配置文件:
mv /etc/samba/smb.conf /etc/samba/smb.conf.bak cat /etc/samba/smb.conf.bak | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf nano /etc/samba/smb.conf
修改成如下:
[global] workgroup = MYGROUP 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 [database] comment = Do not arbitrarily modify the database file path = /home/database public = no writable = yes
若只需要用户的home文件夹能够访问,参考如下设置:
[homes] comment = Home Directories valid users = %S, %D%w%S browseable = No read only = No inherit acls = Yes
注意此处需要创建用户和用户的home文件夹
useradd z7 passwd z7 usermod -a users z7 #增加用户到组 chown -Rf users:z7 /home/ #授权读写
- 添加samba用户
useradd linuxprobe passwd linuxprobe pdbedit -a -u linuxprobe
创建linuxpobe的文件存储位置
mkdir /home/database chown -Rf linuxprobe:linuxprobe /home/database semanage fcontext -a -t samba_share_t /home/database
检查配置selinux中的samba
getsebool -a | grep samba
若开启了selinux的需要设置
setsebool -P samba_enable_home_dirs on
- 开启samba
systemctl restart smb systemctl enable smb
若不能访问,需要检查防火墙
- win10下测试
传输和删除测试:通过
参考资料:
- https://www.linuxprobe.com/chapter-12.html