首页 > 技术文章 > 安装SAMBA服务

lych2e 2015-11-08 18:00 原文

在虚拟机VMWare 10中安装了ubuntu 14.04 LTS,但无法使用共享文件夹功能,只能转向samba

1. 安装samba服务

sudo apt-get install samba

2. 配置samba

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo vi /etc/samba/smb.conf

输入以下内容:

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = ubuntu
security = user

map to guest = bad user
dns proxy = no
###### Share Definitions ######
[Anonymous]
path = ubuntu中共享文件夹路径
browsable =yes
writable = yes
guest ok = yes
read only = no

3. 重启samba服务

sudo service smbd restart

4. Windows中访问Ubuntu共享文件夹

在文件夹地址栏输入\\ubuntu IP,即可看到共享文件夹

参考资料:

(1) samba在ubuntu 14.04中的配置
(2)  官方文档

##############################################

对于在centos,配置samba的方法有所不同

1. centos不会自动启动samba服务,需要手工设置:

chkconfig smb on
chkconfig nmb on

2. 需要设置防火墙规则,否则无法访问:

配置/etc/sysconfig/iptables文件,添加

-A INPUT -m state –state NEW -m tcp -p tcp –dport 139 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 445 -j ACCEPT
-A INPUT -m state –state NEW -m udp -p udp –dport 137 -j ACCEPT
-A INPUT -m state –state NEW -m udp -p udp –dport 138 -j ACCEPT

允许139 445 137 138几个端口通过,重启iptable

/etc/rc.d/init.d/iptables restart

3. 修改smb.conf配置

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = centos
security = share
guest account = root
map to guest = bad user
log file = /var/log/samba/%m.log
max log size = 1024
###### Share Definitions ######
[Anonymous]
path = /tmp
writable = yes
read only = no
guest ok = yes
guest only = yes
###### /etc/samba/smbusers ######
root = [用户名,例如root]

4. 如果win下能看到共享文件夹,但无法打开,可能是文件夹的权限问题,尝试使用/tmp作为共享

5. 如果win无法copy共享文件,需要关闭selinux:

setenforce 0

默认的selinux不允许网络上对samba共享目录做修改,即使smb.conf配置了允许

参考资料:

1. Easy Samba server installation on CentOS 6.5
2. CentOS配置smaba与Windows共享文件
3. Guest account配置

推荐阅读