我配置 ssh 授权以删除一些具有脚本中定义的规则的用户,并在他们登录时为他们提供一些扩展功能。我使用两个 pam 模块 - pam_script 和 pam_cap,并更改 sshd pam 配置 (/etc/pam.d/sshd),使其看起来像这样(只有前两行是自定义的):
#%PAM-1.0
auth required pam_script.so
auth required pam_cap.so
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
允许密码验证,现在用户可以通过 Pkey 或密码进行授权。如果用户通过密码授权,pam_script 可以正常工作,并且那些不符合规则的用户将被删除。但是,如果同一用户通过 Pkey 授权,则 pam auth 部分似乎被绕过,pam_script 根本不被调用。sshd 在使用 Pkey 授权用户时不使用 pam auth 吗?
答案1
PAM 用作 KeyboardAuthentication 子系统,不由 PubkeyAuthentication 调用。您可以在创建会话时删除用户,而不是进行身份验证。