CentOS 7 搭建 Samba 服务器

安装 Samba

1
sudo yum -y install samba samba-client samba-common

检查是否安装成功

1
rpm -qa | grep samba

Configure Samba
ShareName Path Rights
SHAREDOCS /smb/docs All include guest
RDDOCS /smb/tech Only users in group

创建共享目录

1
2
sudo mkdir -p /smb/docs
sudo mkdir -p /smb/tech

创建用户

1
2
sudo useradd cosmo
sudo useradd RD

修改用户组

1
sudo usermod -a-G RD cosmo

检查用户组

1
id cosmo

创建Samba用户

1
smbpasswd -a cosmo

修改目录权限

1
2
3
4
5
6
sudo chgrp RD /smb/tech
sudo chgrp RD /smb/docs
sudo chown RD /smb/tech
sudo chown RD /smb/docs
sudo chmod 770 /smb/tech
sudo chmod 777 /smb/docs

检查权限

1
ls /smb -l

备份原有配置文件

1
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.origin

修改配置文件

1
sudo vim /etc/samba/smb.conf

—–/etc/samba/smb.comf—–

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[global]
workgroup = WorkGroup
netbios name = File Sever
server string = Samba Server Version %v
security = user
map to guest = Bad User
#如果出现Failed to retrieve printer list: NT_STATUIS_UNSUCCESSFUL错误
;printing = bsd
;printcap name = /dev/null

[SHAREDOCS]
path = /smb/docs
readonly = yes
broseable = yes
guest ok = yes

[RDDOCS]
path = /smb/tech
public = no
writable = yes
write list = @RD
valid user = @RD

重启服务

1
2
3
4
sudo systemctl restart smb
sudo systemctl enable smb
sudo systemctl reload smb
sudo systemctl status smb

防火墙开放端口

1
2
3
4
5
6
7
8
# For Firewall
sudo firewall-cmd --permanent --zone=public --add-service=samba
# For iptables
## 入站规则
iptables -A INPUT -p tcp -m multiport --dports 139,445 -j ACCEPT iptables -A INPUT -p udp -m multiport --dports 137,138 -j ACCEPT
## 出站规则
iptables -A OUTPUT -p tcp -m multiport --sports 139,445 -j ACCEPT
iptables -A OUTPUT -p tcp -m multiport --sports 137,138 -j ACCEPT

需要关闭 SELinux

1
2
3
sudo vim /etc/selinux/config
selinux=disabled #######
sudo reboot

联通测试 Linux

1
smbclient -L localhost -U cosmo

CentOS 7 搭建 Samba 服务器
https://blog.yuhaogao.com/2016/03/02/CentOS-7-搭建-Samba-服务器/
作者
宇皓
发布于
2016年3月3日
许可协议