—-Pluggable Authentication Modules — 可插入认证模块
PAM是 Sun公司于1995 年开发的一种与认证相关的通用框架机制,关注如何为服务验证用户的API通过提供一些动太链接库和一套统一的API将系统提供的服务和该服务的认证方式分开
PAM认证原理
PAM认证一般遵循这样的顺序: Service(服务)→PAM(配置文件)→pam_*.so
PAM认证首先要确定那一项服务,然后加载相应的PAM的配置文件(位于/etc/pam.d下),最后调用认文件(位于/lib/security下)进行安全认证PAM认证机制
当用户以某一账号进行/usr/bin/sudo 程序时,sudo 会联系PAM模块,PAM模块会搜寻sudo程序的PAM相关设定配置, 查看sudo的相关模块进行命令的验证,将验证结果回传给程序,而程序会根据PAM回传的结果执行下一个动作
相关文件:
模块文件目录 /lib64/security/*.so 环境相关设置目录:/etc/security 主配置文件 :/etc/pam.conf 应用专用配置目录:/etc/pam.d /etc/pam.d/ 与 /etc/pam.conf的优先级为 /etc/pam.d内的文件高于pam.conf的配置文件
配置文件内的格式
/etc/pam.conf 格式 application type control module-path arguments /etc/pam.d/* 格式 type control module-path arguments 配置文件pam.conf因为没有特别的标明使用到哪个程序,所以我标上程序名称,而pam.d是只针对某一程序软件的,文件名已经指明。 application: 应用软件名称,如 su sudo ssh 等等 type: 类型指的是模块类型如 (auth account session ...) control: PAM定义使用的模块成功与失败该如何执行下一部操作 module-path 用来指明模块对应的模块文件路径名 Arguments 用来传递给该模块的参数
类型:type
Auth: 账号的认证和授权 Account 与账号管理相关的非认证类的功能,对用户进行限制 Password 用户修改密码复杂度检查等功能 session 用户获取到服务之前或使用服务完成之后需要进行一些附加的操作 - 加 type 表示因为缺失而不能加载的模块将不记录到系统日志,对那些不总是安装在系统上的模块有用
控制:Control的几种格式
control有简单和复杂两种, 简单的: required 表示本模块必须返回成功才能通过,如果不成功则继续动行接下来的规则,等全部运行完再返回执行失败的结果给应用程序 requisite: 表示模块必须返回成历才能通过,一旦返回失败,将不再执行同一个type的模块,直接将控制权返回给应用程序 sufficient 表明本模块返回成功则通过身份认证的要求,不必再执行同一type的模块,如果不成功可忽略,继续执行下一条 optional 表明模块是可选的,它的成功与否不对认证起关键作用,返回值一般是被忽略的 include 调用其它配置文件中定义的规则信息 复杂的,如: 【status1=action1 status=action2 ...】 * status: 检查结果的返回状态 action:采取的行为 action: ok :模块通过,继续检查 done :模块通过,返回最后结果 bad :结果失败,继续检查 die :结果失败,返回失败结果 ignore :结果忽略,不影响最后的结果 reset :忽略已经得到的结果
module-path: 模块路径
相对路径: /lib64/security 目录下的模块可使用相对路径 如: pam_shells.so 、 pam_limits.so 绝对路径: /etc/security/*.conf Arguments 用来传递给该模块的参数
Note:PAM配置文件一旦修改或创建,将马上生效
模块:pam_shells.so 功能: 检查/etc/shells已有的shell 如果配置文件内有的就让其登陆,如果没有就不允许 首先,查找到su在pam.d的文档进行编辑 [root@CentOS6 pam.d]#vim su 1 #%PAM-1.0 2 auth required pam_shells.so 我们在第一行添加,因为如果违反规则无需其它操作 3 auth sufficient pam_rootok.so 其它的选择默认不动 4 # Uncomment the following line to implicitly trust users in t he "wheel" group. 5 #auth sufficient pam_wheel.so trust use_uid 6 # Uncomment the following line to require a user to be in the "wheel" group. 7 #auth required pam_wheel.so use_uid 8 auth include system-auth 9 account sufficient pam_succeed_if.so uid = 0 use _uid quiet 10 account include system-auth 11 password include system-auth 12 session include system-auth 13 session optional pam_xauth.so 接下来查看下/etc/shells里有哪些支持shell 然后创建一个不支持shell的测试用户 useradd -s /bin/csh testuser echo "testuser" |passwd --stdin testuser testuser:x:501:501::/home/testuser:/bin/zsh 接下来测试 [root@CentOS6 pam.d]#su - testuser Password: su: incorrect password su 无法切换到指定用户,并不是密码错误。 [root@CentOS6 pam.d]# 我们删除之前加进到/etc/pam.d/su 的第一条规则之后测试下结果 [root@CentOS6 pam.d]#su - testuser [testuser@CentOS6 ~]$ 成功切换
limits 限额有个两种方式
1. ulimit 命令 也是可以设置限额功能, 但无法进行保存的,因为是执行在内存中。
ulimit -a 显示所有ulimit 参数信息 -n 最多的打开的文件描述符个数 -u 最大用户进程数 -S 使用soft(软)资源限制 -H 使用hard (硬)资源限制
2.limits 限制的配置文件限额
配置文件: /etc/security/limits.conf 或 /etc/security/limits.d/*.conf cat /etc/security/limits.conf # /etc/security/limits.conf # #Each line describes a limit for a user in the form: # #文档已经给出了参数信息,也给了一定的事例 # #Where: # 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 # # can have the two values: # - "soft" for enforcing the soft limits # - "hard" for enforcing hard limits # # - 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 # #
这块给出的事例... # #* 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 [root@CentOS6 security]# 当使用到web服务的时候,有时候apache如果是默认的限额的话那么有时候用户访问量过大,限额就要提 高,所以可以从这里进行配置