pam模块的配置使用

pam模块的配置使用

先看一个配置文件

cat /etc/pam.d/sshd
#%PAM-1.0
auth       required pam_sepermit.so
auth       substack     password-auth
auth       include      postlogin
# Used with polkit to reauthorize users in remote sessions
-auth      optional     pam_reauthorize.so prepare
account    required     pam_nologin.so
account    include      password-auth
password   include      password-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open env_params
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      password-auth
#session    include      postlogin
# Used with polkit to reauthorize users in remote sessions
-session   optional     pam_reauthorize.so prepare

第一列: 是认证类型
第二列:控制标记
第三列:认证模块
下边仔细说明一下这三列

先说第二列控制标记

解释:控制标记简单的解释是就是各个模块的重要程度。

  • required
    该标记的模块认证成功是用户通过的必要条件。就是说required标记的模块如果认证失败,就一定不会通过认证。认证失败以后也不会立刻返回给用户错误消息,而是在所有的模块调用完毕以后统一返回,就是说该模块认证失败以后其他的模块认证没有意义了。这样做的目的是为了迷惑“敌人”,让他们不知道是哪个模块认证失败导致的问题。
  • requisite
    该标记的模块 required的相似,它标记的模块认证失败以后会直接返回给应用,不会执行接下来的模块,而该标记一般用在认证一开始,用来判断用户的登录环境是否合法,如果不合法的话直接返回认证失败,就算是合法的用户,如果登录环境不对也不会通过认证。
  • sufficient
    该标记的模块标识的是用户通过认证的充分条件,意思就是只要该模块通过了认证就会立刻返回给用户认证成功。当然sufficient的优先级低于required,如果required认证失败了最终结果也是失败。当sufficient认证失败的时候就相当于optional
  • optional
    该标记的模块认证失败,用户也能通过认证。就是该标记的模块一般只做信息的展示,不去做认证相关的东西,用户的认证能否通过全部取决于上边三个标记。
  • include
    该标记实际上就是引用这个pam文件相同的目录下的另一个文件。但是不会将另一个pam配置文件中的所有内容引入,只会对“模板类型”字段所标记的一类模块起到作用。即便system-auth可能包含了全部的四种类型的模块,也只有当前记录所对应的哪一类模块的那些记录包含进来。解释一下
auth       include      postlogin
account    include      password-auth
password   include      password-auth
session    include      password-auth

上边的配置文件中有这三条记录,password-auth这个文件被引用了三次,查看password-auth中的记录auth account password session四种类型的模块都有。如下配置文件

# cat password-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        required      pam_faildelay.so delay=2000000
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 1000 quiet_success
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     required      pam_permit.so

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok


password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
-session     optional      pam_systemd.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
 account    include      password-auth

该条记录只会引用password-auth中的如下这些配置

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     required      pam_permit.so
password   include      password-auth

该条记录只会引用password-auth中的如下这些配置

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password    required      pam_deny.so

你懂得

  • 认证的流程

在配置文件有存在逻辑的一些认证

一下内容是我从pam.d下的配置文件中摘取出来的一些具有逻辑的配置。

auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
session    optional     pam_keyinit.so force revoke
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
[]中的就是细致定义的控制标记,意思是:user_unknown的返回忽略, seccess的返回执行ok动作,ignore的返回执行ignore动作,default状态返回执行bad动作
问题:[user_unknown=ignore success=ok ignore=ignore default=bad]列表中的认证是顺序认证还是与或非或者是模块只会给与一个返回??????

这些就是细致描述模块的返回状态的处理方式,类似user_unknown、sucess、ignored等这些内容就是某个模块的返回状态。那么相应的ignore、ok、bad等就是对这些返回状态的处理方式,或者说是动作

  • pam所支持的动作列表
标记 说明
ignore 忽略这个状态,不会对验证结果产生影响
bad 表示这个返回状态代表验证失败、余下的模块调用也永远失败
die 与bad相同,但是应该立即返回到应用,不在继续调用余下模块
ok 标识这个返回状态应该被看作是验证成功,继续调用余下模块
done 与ok相同,但是应该立即返回到应用,不在继续调用余下模块
N 与ok相同,但是要跳过N个模块才能继续
reset 清楚所有的返回状态、继续调用余下模块
  • pam常见的返回状态
状态 说明
success 认证成功
auth_err 认证失败
new_authtok_reqd 需要新的认证令牌。有三种情况会返回这个状态:1. 根据安全策略需要更密码,2. 是密码为空;3. 是密码已经过期
ignore 忽略底层account类型模块的返回状态,而且无论是否被required、sufficient和optional修饰。处于安全考虑,这个返回状态通常需要被忽略掉,这样其他模块的返回状态会被参考
user_unknown 未知用户
try_again 已经通过了密码服务的初步检测
default 所有没有注明的返回状态
account     sufficient    pam_succeed_if.so uid < 1000 quiet
这种配置和这个模块有关的,能在pam配置文件中实现一些分支结构,就像uid < 1000如果登录用户是uid返回1000那么就会返回sucess状态

-session   optional     pam_ck_connector.so
这个-session的意思是这个模块的返回信息不回记录在日志中,日志一半就是在/var/log/secure

猜你喜欢

转载自www.cnblogs.com/yanghehe/p/12294128.html
pam