samba详解

Samba详解 

原文  http://blog.csdn.net/seward_wang/article/details/12614263

samba-client.i386
samba-common.i386
samba.i386
samba-swat.i386

1、安装软件包
# yum install samba* -y

配置目录 /etc/samba

man smb.conf

# vim /etc/samba/smb.conf

[global]
        workgroup = MYGROUP
        server string = Samba Server Version %v
        security = user
        passdb backend = tdbsam
        load printers = yes
        cups options = raw

[homes]
        comment = Home Directories
        browseable = no
        writable = yes
[printers]
        comment = All Printers
        path = /var/spool/samba
        browseable = no
        guest ok = no   # <--- yes匿名可以访问,no拒绝匿名访问
        writable = no   # <--- yes 资源可以写,no只读
        printable = yes

[share]
comment = This is rhce testing
path = /common
browseable = yes # <---让资源可见
hosts allow = .example.com  # <---只允许example.com域下的用户访问
valid users = user1  # <---该资源只对user1用户有效,别的用户不能访问
writable = yes  # <--资源可写
2、创建目录并且修改selinux上下文

# mkdir /common
# chmod 775 /common

# chcon -R -t samba_share_t /common
# setsebool -P samba_export_all_ro on
或者
# setsebool -P samba_export_all_rw on

3、创建samba独立的帐号
注意:这些帐号必须是系统上本身就拥有的帐号

[  useradd user1  ]

# smbpasswd --help

# smbpasswd  -a user1 <---添加user1到smb专用的帐号数据文件里
4、设定iptables
samber有两个进程:
nmbd 137 , 138
smbd 139 , 445

iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 137,138,139,445 -j ACCEPT
iptables -A INPUT -p udp -m multiport --dports 137,138,139,445 -j ACCEPT
5、测试
# service smb restart

# smbclient -L //192.168.0.249 -U user1   <--列出可以访问的资源
# smbclient //192.168.0.249/share -U user1 <--访问名字叫share的资源
如果共享的目录是公共的目录,也就是该目录也被别的服务共享,selinux上下文这样设定:
# chcon -t public_content_t /common
# chcon -t public_content_rw_t /common/pub

总结:
如果/common目录被nfs,vsftp,samba同时共享出去
selinux设定:
如果要求对该目录有写的权限:
chcon -R -t public_content_rw_t /common
如果是只读:
chcon -R -t public_content_t /common

文件系统权限:
如果要求对该目录有写的权限:
chmod 775 /common
chown root:XXXX /common   《 --XXXX代表通过samba在该目录写文件的哟用户所在的组
iptables设定(samba,nfs,ftp):

modprobe ip_conntrack_ftp  <- --非常重要
echo "modprobe ip_conntrack_ftp"  >> /erc/rc.d/rc.local iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 20,21,137,138,139,445,875,32803,32769,892,662,2020,111,2049 -j ACCEPT

iptables -P INPUT DROP

练习:

1、通过samba共享/common目录,要求不允许t113.org域的所有用户访问。只允许user2访问该资源

[share]
comment = "test"
path = /common
hosts deny = .t113.org
valid users = user2

useradd user2
smbpasswd -a user2

2、分别通过smbclient访问用户的家目录资源,测试是否支持上传等操作
给我找到和samba家目录有关的selinux布尔值设定
getsebool 命令 找到
# getsebool  -a | grep samba
samba_domain_controller --> off
samba_enable_home_dirs --> off  《-----
samba_export_all_ro --> off
samba_export_all_rw --> on
samba_share_nfs --> off
use_samba_home_dirs --> off  《-----
virt_use_samba --> off

setsebool -P samba_enable_home_dirs=1
setsebool -P use_samba_home_dirs=1

3、通过samba共享/share目录,要求所有人都可以访问,而且匿名也可以访问,并且匿名也可以上传文件。

[pub]
comment = "Public source"
path = /share
guest ok = yes
browseable = yes
writable = yes

# chcon -t public_content_rw_t /share/

还需设定目录权限和selinux策略
chmod 777 /share
setsebool -P allow_smbd_anon_write=1

测试
# smbclient -L //192.168.0.249
# smbclient  //192.168.0.249

posted @ 2014-06-04 20:57  搞程序太虐心  阅读(710)  评论(0编辑  收藏  举报