SamBa-Server

Samba共享服务器搭建

1.使用yum 命令安装Samba4及所需要的包

1
yum install samba samba-client samba-common

2. 安装好samba包后,将samba服务添加到允许通过Linux防火墙中

1
2
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload

PS:firewall常用命令:firewall.service服务
service firewalld restart 重启
service firewalld start 开启
service firewalld stop 关闭

http://blog.csdn.net/xlgen157387/article/details/52672988

3. 备份Samba的配置文件/etc/samba/smb.conf

1
cp /etc/samba/smb.conf /etc/samba/smb.conf.orig

4. 新建用户和组,将用户加到组里 (通过组权限和所有者,可快速实现对同一个文件夹,给不同用户设置不同权限)

1
2
3
useradd tecmint
groupadd smbgrp
usermod tecmint -aG smbgrp

5. 创建一个共享文件目录(这里是根目录/srv目录下) /srv/samba/secure, 并设置文件目录的所有者以及所属组,以及相对应的权限

1
2
3
mkdir -p /srv/samba/secure
chmod -R 0770 /srv/samba/secure
chown -R root:smbgrp /srv/samba/secure

6. 修改SELinux安全内容,设置samba共享路径

1
chcon -t samba_share_t /srv/samba/secure

PS:
if you got error chcon: can’t apply partial context to unlabeled file ‘/home/Shared_folder’, using full label for directory. because this directory dosen`t have any label, so it cant get a partial label.(you can see current label with ls -Z).
use below command to set full label for it:
chcon -h system_u:object_r:samba_share_t /home/Shared_folder
chcon -R -h system_u:object_r:samba_share_t /home/Shared_folder*

参考连接:https://superuser.com/questions/524672/unable-to-connect-to-samba-shared-folder-via-windows

7. 打开samba 配置文件 编辑Secure文件的共享设置信息并保存退出。

1
2
3
4
5
6
7
8
9
vi /etc/samba/smb.conf
Samba Secure Configuration Settings
[Secure]
comment = Secure File Server Share
path = /srv/samba/secure
valid users = @smbgrp
guest ok = no
writable = yes
browsable = yes

8. 检查确认samba配置信息已经修改好

1
testparm

9. 启动samba服务

1
2
3
4
systemctl enable smb.service
systemctl enable nmb.service
systemctl start smb.service
systemctl start nmb.service

10. 给用户设置一个进入共享的密码

1
smbpasswd -a tecmint

参考连接:https://www.tecmint.com/install-samba4-on-centos-7-for-file-sharing-on-windows/

11. 用户及文件夹的权限配置:

参考连接:https://blog.csdn.net/lan120576664/article/details/50396511

分享到