一、samba匿名共享搭建:

mount /dev/cdrom /mnt

vi /etc/yum.repos.d/rhel.repo

[local]

name=lcoal

baseurl=file:///mnt

enabled=1

gpgcheck=0

:wq

关闭selinux

yum -y install samba

vi  /etc/samba/smb.conf   ##修改主配置文件

##删除注释:%g /^#/d  删除空行:%g /^$/d  删除样例行:%g /^;/d  删除多余空行;修改如下:

[global]


        workgroup = MYGROUP

        server string = Samba Server Version %v

        log file = /var/log/samba/log.%m

        max log size = 50

        security = share

        passdb backend = tdbsam

        load printers = yes

        cups options = raw

[public]

        comment = Public Stuff

        path = /opt/share

        public = yes

        writable = yes

        printable = no

:wq

mkdir  /opt/share

touch /opt/share/a.file

chmod 777 /opt/share

testparm   ##测试配置是否有误

/etc/init.d/smb  start

chkconfig smb on

netstat -utpln |grep mb  ##TCP:139,445/UDP:137,138查看端口


防火墙配置:

iptables -I INPUT -m multiport -p tcp --dports 22,139,445 -j ACCEPT


iptables -I INPUT -m multiport -p udp --dports 137,138 -j ACCEPT

iptables -P INPUT DROP

iptables -P FORWARD DROP

iptables -I INPUT -m state --state ESTABLISHED -j ACCEPT

iptables -I INPUT -i lo -j ACCEPT

/etc/init.d/iptables save


测试:

windows:

\\ip地址\public


二、samba用户认证的共享:注意匿名和认证选一个

创建用户:

useradd u01

useradd u02

pdbedit -a u01  ##将系统用户添加为smb用户

pdbedit -a u02

pdbedit -L  ##查看smb用户

修改配置文件:

[root@smb ~]# vi /etc/samba/smb.conf

[global]


        workgroup = MYGROUP

        server string = Samba Server Version %v

        log file = /var/log/samba/log.%m

        max log size = 50

        security = user    ##用户认证的共享

        passdb backend = tdbsam

        load printers = yes

        cups options = raw

[public]

        comment = Public Stuff

        path = /opt/share

        public = no   ##共享非公开

        writable = no   ##默认不可以写

        valid users = u01, u02  ##允许访问的用户

        write list = u01  ##有写入权限的用户

:wq

testparm

/etc/init.d/smb  restart

netstat -utpln |grep mb

防火墙......

测试......