zoukankan      html  css  js  c++  java
  • nsswitch & pam

    nsswitch: network service switch,网络服务切换

    解析库:
      文件、mysql、NIS、LDAP、DNS

    与各存储交互实现的通用框架

    通用框架存放位置:/usr/lib64/libnss*, /lib64/libnss*

    配置文件中要配置使用哪个解析库

    配置文件: /etc/nsswitch.conf
       配置示例: db: store1 store2 ...

    有一个手动解析的命令:getent

    # getent database [entry]
        示例:get passwd root
           get services http

    每种存储中查找的结果状态: STATUS => success | notfound | unavil | tryagain
    对应于每种状态参数的行为: ACTION => return | continue

    示例: host: files nis [NOTFOUND=return] dns  //nis不可用时才去找dns

    pam: pluggable authentication module,插入式认证模块

    认证库:
      文件、mysql、LDAP、NIS

    通用框架:与各存储交互的实现,以及多种辅助性功能

    通用框架存放位置:/lib64/security/
    配置文件: 
      /etc/pam.conf,
      /etc/pam.d/*.conf   

    通常每个应用使用单独的一个配置文件

    配置文件中每行定义一种检查规则
    格式:
    type   control   module-path   module-arguments 
    type: 检查功能类别 
        auth:账号的认证和授权
        account: 与账号管理相关的非认证功能
        password: 用户修改密码时密码检查规则
        session:用户获取到服务之前或使用服务完成之后要进行的一些附加性操作
    control: 同一种功能的多个检查之间如何进行组合
        有两种实现机制:
          1.使用一个关键词来定义,例如sufficient,required, requisite
          2.使用一个或多个"status=value"形式的组合表示
        
          简单机制
            required: 如果检查通过,后续依然要检查;如果检查不通过,即使后面通过了也照样不通过
            requisite: 如果通过了继续后面检查,如果不通过直接返回不通过
            sufficient: 如果通过,后面不需要检查直接通过了;如果检查没通过,看其他检测结果通过还是不通过
            optional:可选的
            include: 包含进来其他相同类型的规则
      
          复杂机制: [status1=action1,status2=action3,...]
                  status: 返回状态
                  action: ok, done, die, ignore, bad, reset
                    ok:一票通过权
                    done: 通过就通过了,不通过就不通过了
                    die:一票否决权
                    ignore: 忽略
    module-path: 模块路径
        /lib64/security:此目录下的模块引用时可使用相对路径

    module-arguments:模块参数

    模块
    1. pam_shells.so

    实例:假设我们去掉了/etc/shells文件中的/bin/bash,

    检查登录shell

    # cd /etc/pam.d
    # vim sshd
        添加:auth    required     pam_shells.so

    登出shell重新连接就不能连接了,添加/bin/bash后重新远程连接就可以了

    2. pam_limits.so
    模块通过读取配置文件完成用户对系统资源的使用控制

    配置文件:/etc/security/limits.conf
         /etc/security/limits.d/*

    # /etc/security/limits.conf
    #
    #Each line describes a limit for a user in the form:
    #
    #<domain> <type> <item> <value>
    #
    #Where:
    #<domain> can be:
    # - a user name
    # - a group name, with @group syntax
    # - the wildcard *, for default entry
    # - the wildcard %, can be also used with %group syntax,
    # for maxlogin limit
    #
    #<type> can have the two values:
    # - "soft" for enforcing the soft limits
    # - "hard" for enforcing hard limits
    #
    #<item> can be one of the following:
    # - core - limits the core file size (KB)
    # - data - max data size (KB)
    # - fsize - maximum filesize (KB)
    # - memlock - max locked-in-memory address space (KB)
    # - nofile - max number of open file descriptors
    # - rss - max resident set size (KB)
    # - stack - max stack size (KB)
    # - cpu - max CPU time (MIN)
    # - nproc - max number of processes
    # - as - address space limit (KB)
    # - maxlogins - max number of logins for this user
    # - maxsyslogins - max number of logins on the system
    # - priority - the priority to run user process with
    # - locks - max number of file locks the user can hold
    # - sigpending - max number of pending signals
    # - msgqueue - max memory used by POSIX message queues (bytes)
    # - nice - max nice priority allowed to raise to values: [-20, 19]
    # - rtprio - max realtime priority
    #
    #<domain> <type> <item> <value>
    #

    #* soft core 0
    #* hard rss 10000
    #@student hard nproc 20
    #@faculty soft nproc 20
    #@faculty hard nproc 50
    #ftp hard nproc 0
    #@student - maxlogins 4

    # End of file

    <domain>
        username
        @group
        *: 所有用户
    <type>
        soft:用户可自行修改,但不能超过hard限制
        hard: 由root设定,通过kernel强制生效
        -: 两种都限定
    <item>
        nofile: 所能够同时打开的最大文件数量
        nproc:所能够同时运行的最大进程数量
        msgqueue:所能够使用的POSIX消息队列能够占用的最大内存空间
        sigpending: 所能够使用的最大信号数量
    <value>

     举例:

    用户常用调整:
    ulimit
    -n #: 文件数量 ulimit -u #: 进程数量
  • 相关阅读:
    资料-Java基础:多线程--创建启动线程的多种方式
    资料-Java基础:基础总结-运算符
    资料-Java基础:父子类加载过程
    总结提纲-逐渐补充
    资料-Java基础:类加载处理过程
    资料-Java基础:双亲委派模型
    资料-Java基础:类加载方式及差异
    转载:java 泛型详解-绝对是对泛型方法讲解最详细的,没有之一
    无法启动IIS Express web服务,端口正在使用!
    关于在本地新建数据库作业,无法成功的问题【本地SQLSERVER链接的服务器数据库】
  • 原文地址:https://www.cnblogs.com/ckh2014/p/10828266.html
Copyright © 2011-2022 走看看