CentOS下Samba使用

1. 软件

Samba需要以下三个基本软件包,相关依赖包未列出

samba: The Samba SMB server
samba-client: Samba (SMB) client programs
samba-common: Files used by both Samba servers and clients
[optional]samba-swat: The Samba SMB server WEB configuration program

2. 启动

安装完成后,可使用如下命令启动Samba服务

# /etc/init.d/service smb start

如果想让Samba服务开机自动加载,可使用[ntsysv]打开开机自动加载的服务或使用chkconfig命令来完成

# /sbin/chkconfig --level 3 smb on
# /sbin/chkconfig --level 5 smb on

对于CentOS 7,使用的命令如下

# systemctl start smb.service
# systemctl enable smb.service

3. 防火墙

默认情况下Samba服务器是无法通过防火墙的;要正常使用Samba服务器,可以关闭防火墙或放开相关端口

smbd: 139(TCP) 445(TCP) 
nmbd: 137(UDP) 138(UDP)

防火墙配置的命令如下

# service iptables stop
# vi /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
# service iptables restart

对于CentOS 7,配置命令如下

# firewall-cmd --permanent --add-service=samba
# firewall-cmd --reload
# setsebool -P samba_enable_home_dirs on  /* 配置SeLinux */

4. 简单配置

Samba服务器的配置文件是 /etc/samba/smb.conf

4.1 新增用户

下面的命令新增Samba用户 lfs/lfs

root:/home/lfs# smbpasswd -a lfs 
New SMB password:          /* type “lfs” */ 
Retype new SMB password:   /* type “lfs” */ 
Added user lfs. 
root:/home/lfs#

4.2 共享配置

修改/etc/samba/smb.conf,加入下面几行

[LFS] 
        comment = LFS Directories
        path = /mnt/lfs
        browseable = yes
        writable = yes
        valid users = lfs

参考:
<Linux Samba配置>
<CentOS7下Samba的安装与配置>

posted @ 2013-09-02 20:25  北落不吉  阅读(1312)  评论(0编辑  收藏  举报