Blog

  • samba配置文件分布式写法

    要求:有两个部门A和B,分别分配一个区,A部门人员不能看到B区,B部门人员也不能看到A区,同时有共享区share,两部门都可以自由使用。

    如果不采用分布式写法,则用户能看到所有区,但只能进入有权限的区,虽可实现使用,但不符合要求,只要按相同的方法,分布式写配置文件,可控制samba用户只看到自己有读权限的文件和文件夹。

    vi /etc/samba/smb.conf

    #%U代表单独用户,%G代表用户组的配置文件

    include = /etc/samba/smb.conf.%U
    include = /etc/samba/smb.conf.%G

    这时我jpuyy,如果在A组,则把我加入到A的用户组里,关键点,是将jpuyy的首选组设为A,(如果不这样,可能会产生看不到A的情况),命令是:

    usermod -g A jpuyy

    然后在 /etc/samba/下添加一个A组的配置文件

    vim smb.conf.A

    添加

    [A-读写]
    comment = A区
    path = /home/data/A
    valid users = @A
    write list = @A

    当然也可以针对用户来写,同理就是规定了这个用户的权限了。

    参考:http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html

  • SAMBA文件服务器部署

    以下操作适用于CentOS6.2 x64

    1.关闭selinux

    vim /etc/selinux/config
    将SELINUX=enforcing用#注释,设为

    SELINUX=disabled

    重启 reboot

    2.安装samba

    yum install cups-libs samba samba-common

    查看smb.conf的[global] 部分

    vi /etc/samba/smb.conf

    确认有如下代码

    [...]
     # Backend to store user information in. New installations should
     # use either tdbsam or ldapsam. smbpasswd is available for backwards
     # compatibility. tdbsam requires no further configuration.
     security = user
     passdb backend = tdbsam
     [...]

    3.设置开机启动smb服务,并启动smb

    chkconfig --levels 235 smb on
    /etc/init.d/smb start

    4.检查防火墙的配置

    vim /etc/sysconfig/iptables

    加入(注意是eth0改为实际的接口名)

    -A INPUT -i eth0 -p tcp -m state --state NEW -m multiport --dports 139,445 -j ACCEPT
    -A INPUT -i eth0 -p udp -m state --state NEW -m multiport --dports 137,138 -j ACCEPT

    重启生效

    service iptables restart

    5.创建部门区

    /home/data/market-read
    /home/data/market-share

    创建个人区

    /home/users/abc
    /home/users/jpuyy

    5.
    建立用户,改变其家目录

    useradd jpuyy -m -d /home/users/jpuyy -s /sbin/nologin
    useradd abc -m -d /home/users/abc -s /sbin/nologin

    为用户分配不同的组

    groupadd finance
    groupadd market
    usermod -a -G finance jpuyy
    usermod -a -G market abc

    将目录权限和用户组对应起来
    如:

    chown -R root:dev /home/data/market-share/
    chmod -R 775 /home/data/market-read/
    chown -R ray:ray /home/users/ray
    chmod -R 775 /home/users/ray

    6.将系统用户添加为smb用户

    smbpasswd -a abc (添加用户用-a)
    smbpasswd -a jpuyy

    ps:smbpasswd –help可以得知

    smbpasswd -d abc  禁用abc
    smbpasswd -e abc  启用abc
    smbpasswd -x abc  删除abc

    要注意,usermod -g和usermod -G的区别

    -g<群组>  修改用户所属的群组。
    -G<群组>  修改用户所属的附加群组。

  • 按时按登录IP记录Linux所有用户操作日志的方法

    转自:http://www.ha97.com/4733.html

    PS:Linux用户操作记录一般通过命令history来查看历史记录,但是如果因为某人误操作了删除了重要的数据,这种情况下history命令就不会有什么作用了。以下方法可以实现通过记录登陆IP地址和所有用户登录所操作的日志记录!

    在/etc/profile配置文件的末尾加入以下脚本代码就可以实现

    #PS1="`whoami`@`hostname`:"'[$PWD]'
    history
    USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
    if [ "$USER_IP" = "" ]
    then
    USER_IP=`hostname`
    fi
    if [ ! -d /tmp/history ]
    then
    mkdir /tmp/history
    chmod 777 /tmp/history
    fi
    if [ ! -d /tmp/history/${LOGNAME} ]
    then
    mkdir /tmp/history/${LOGNAME}
    chmod 300 /tmp/history/${LOGNAME}
    fi
    export HISTSIZE=4096
    DT=`date +"%Y%m%d_%H%M%S"`
    export HISTFILE="/tmp/history/${LOGNAME}/${USER_IP} history.$DT"
    chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null

    通过上面的代码可以看出来,在系统的/tmp新建个history目录(这个目录可以自定义),在目录中记录了所有的登陆过系统的用户和IP地址,这也是监测系统安全的方法之一。

  • 事情弄的差不多,毕业了

    大四这一年,起初上学期的享乐生活,一节课也没有

    后来找工作急急忙忙,找的差不多,后来又回校做毕业设计,答辩

    6月5号,班级聚餐

    6月6号,拍毕业照

    6月11号,求索聚餐

    6月14号,出发,去黄山,毕业旅行,15号,向上爬,晚上睡山上又下雨,16号下山回常州。

    6月22号,拿毕业证,从楼上扔东西,晚上一起逛了最后一次校园。

    6月23号,收拾东西,把他们没拿走的东西贪污掉,卖掉电风扇和被子,交宿舍钥匙,买票离别兄弟们,回南京。

    接下来清理电脑里面的和工作、生活无关的软件和文件

    各种用不到的vpn,宽带上网助手,网银插件,vs2008,sybase power desiner,会声会影。

    清理通讯录,办一张南京的手机号,银行卡,开始南京的生活

    graduate from cczu

  • httpd重启输入key的问题

    [root@sls-bb21p18 private]# openssl rsa < managed.name.key > managed.name.key.nopw
    Enter pass phrase:
    writing RSA key

    openssl rsa -in server.key -out server.key

    回到/etc/httpd/conf.d/ssl.conf,把证书改为managed.name.key.nopw就可以了

  • mysql多表查询

    内部连接 inner join 两表都满足的组合
    full outer 全连 两表相同的组合在一起,A表有,B表没有的数据(显示为null),同样B表有
    A表没有的显示为(null)
    A表 left join B表 左连,以A表为基础,A表的全部数据,B表有的组合。没有的为null
    A表 right join B表 右连,以B表为基础,B表的全部数据,A表的有的组合。没有的为null
    查询分析器中执行:
    –建表table1,table2:
    create table table1(id int,name varchar(10))
    create table table2(id int,score int)
    insert into table1 select 1,’lee’
    insert into table1 select 2,’zhang’
    insert into table1 select 4,’wang’
    insert into table2 select 1,90
    insert into table2 select 2,100
    insert into table2 select 3,70
    如表
    ————————————————-
    table1|table2|
    ————————————————-
    idname|idscore|
    1lee|190|
    2zhang|2100|
    4wang|370|
    ————————————————-

    以下均在查询分析器中执行

    一、外连接
    1.概念:包括左向外联接、右向外联接或完整外部联接

    2.左连接:left join 或 left outer join
    (1)左向外联接的结果集包括 LEFT OUTER 子句中指定的左表的所有行,而不仅仅是联接列所匹配的行。如果左表的某行在右表中没有匹配行,则在相关联的结果集行中右表的所有选择列表列均为空值(null)。
    (2)sql 语句
    select * from table1 left join table2 on table1.id=table2.id
    ————-结果————-
    idnameidscore
    ——————————
    1lee190
    2zhang2100
    4wangNULLNULL
    ——————————
    注释:包含table1的所有子句,根据指定条件返回table2相应的字段,不符合的以null显示

    3.右连接:right join 或 right outer join
    (1)右向外联接是左向外联接的反向联接。将返回右表的所有行。如果右表的某行在左表中没有匹配行,则将为左表返回空值。
    (2)sql 语句
    select * from table1 right join table2 on table1.id=table2.id
    ————-结果————-
    idnameidscore
    ——————————
    1lee190
    2zhang2100
    NULLNULL370
    ——————————
    注释:包含table2的所有子句,根据指定条件返回table1相应的字段,不符合的以null显示

    4.完整外部联接:full join 或 full outer join
    (1)完整外部联接返回左表和右表中的所有行。当某行在另一个表中没有匹配行时,则另一个表的选择列表列包含空值。如果表之间有匹配行,则整个结果集行包含基表的数据值。
    (2)sql 语句
    select * from table1 full join table2 on table1.id=table2.id
    ————-结果————-
    idnameidscore
    ——————————
    1lee190
    2zhang2100
    4wangNULLNULL
    NULLNULL370
    ——————————
    注释:返回左右连接的和(见上左、右连接)

    二、内连接
    1.概念:内联接是用比较运算符比较要联接列的值的联接

    2.内连接:join 或 inner join

    3.sql 语句
    select * from table1 join table2 on table1.id=table2.id
    ————-结果————-
    idnameidscore
    ——————————
    1lee190
    2zhang2100
    ——————————
    注释:只返回符合条件的table1和table2的列

    4.等价(与下列执行效果相同)
    A:select a.*,b.* from table1 a,table2 b where a.id=b.id
    B:select * from table1 cross join table2 where table1.id=table2.id (注:cross join后加条件只能用where,不能用on)

    三、交叉连接(完全)

    1.概念:没有 WHERE 子句的交叉联接将产生联接所涉及的表的笛卡尔积。第一个表的行数乘以第二个表的行数等于笛卡尔积结果集的大小。(table1和table2交叉连接产生3*3=9条记录)

    2.交叉连接:cross join (不带条件where…)

    3.sql语句
    select * from table1 cross join table2
    ————-结果————-
    idnameidscore
    ——————————
    1lee190
    2zhang190
    4wang190
    1lee2100
    2zhang2100
    4wang2100
    1lee370
    2zhang370
    4wang370
    ——————————
    注释:返回3*3=9条记录,即笛卡尔积

    4.等价(与下列执行效果相同)
    A:select * from table1,table2