企业应用案例

ZMM是一家网站设计公司,下面有运营部,设计部,开发部和运维部,为了加强部门的互联互通,优化工作流程和提高效率,现部署一台Samba服务器。

根据公司情况,需要创建5个一级目录,和公共目录下的四个共享目录;公共共享目录每个部门一个目录。部门内员工可以在部门的一级目录内建立目录和文件,在公共目录内的二级部门目录,可以互相访问;一级目录各部门不可互访,公共目录内可以。

1 创建各级共享目录

[root@localhost~]# 

mkdir -p /ZMM/{sales,desgin,develop,ops,share/{sales,desgin,develop,ops}}


2 创建用户 为每个部门创建3个用户,并创建共享目录管理员

 用脚本批量创建用户

vim userad.sh

#!/bin/bash

bumen=(sales desgin develop ops)

for i in ${ bumen[@] }

    do

        groupadd $i

        for u in $(seq 1 2 3)

            do

                useradd -M -s /sbin/nologin -g ${i} ${i}$u

            done

    done

[root@localhost~]# chmod a+x useradd.sh

[root@localhost~]# sh useradd.sh

[root@localhost~]# smbpasswd -a sales1 #逐个为各个部门用户设置不同密码


3 修改Samba配置文件,设置共享权限

vim /etc/samba/smb.conf

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

[global]

workgroup = MYGROUP

server string = ZMM.corp share

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

max log size = 50

security = user

passdb backend = tdbsam

load printers = yes

cups options = raw 

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

[homes] 

comment = Home Directories

browseable = no 

writable = yes 

###*******************###

[sales]

comment = sales share

path = /ZMM/sales

browseable = yes

guest ok = no

writable = no

writelist = @sales

###*******************###

[design]

comment = design share

path = /ZMM/design

browseable = yes

guest ok = no

writable = no

writelist = @design

###*******************###

[develop]

comment = develop share

path = /ZMM/develop

browseable = yes

guest ok = no

writable = no

writelist = @develop

###*******************###

[ops]

comment = ops share

path = /ZMM/ops

browseable = yes

guest ok = no

writable = no

writelist = @ops

###*******************###

[share]

comment = comment share

path = /ZMM/share

browseable = yes

guest ok = no

writable = yes


4 修改权限启动服务

[root@localhost~]# chmod 1770 /ZMM/{sales,design,develop,ops}  #添加S位权限

[root@localhost~]# chmod 1777 /ZMM/share

[root@localhost~]# chown :sales /ZMM/sales

[root@localhost~]# chown :design /ZMM/design

[root@localhost~]# chown :develop /ZMM/develop

[root@localhost~]# chown :ops /ZMM/ops

[root@localhost~]# service smb start