配置 macOS 以使用仅智能卡认证
智能卡认证为 macOS Sierra 及更高版本提供了强大的双重认证功能。macOS High Sierra 10.13.2 及更高版本支持仅智能卡认证来强制使用智能卡,这会停用所有基于密码的认证。
本文适用于那些在需要智能卡认证的企业环境中设置安全策略的系统管理员。
启用仅智能卡登录
请务必严格按照以下步骤操作,以确保用户能够登录电脑。
将智能卡与某个管理员用户帐户配对,或配置属性匹配功能。
如果你已启用严格证书检查,请安装所需的任意根证书或中间证书。
确认你可以使用智能卡登录管理员帐户。
安装包含“仅智能卡配置描述文件所示。
确认你仍可使用智能卡登录。
有关智能卡有效负载设置的更多信息,请参阅“Apple Configuration Profile Reference”(Apple 配置描述文件参考)。
有关使用智能卡服务的更多信息,请参阅“macOS 部署参考”,或打开“终端”并输入 man SmartCardServices
。
停用仅智能卡认证
如果你通过手动方式管理电脑上安装的描述文件,则可通过两种方式来移除仅智能卡描述文件。你可以使用“系统偏好设置”的“描述文件”面板,也可以使用 /usr/bin/profiles 命令行工具。有关更多信息,请打开“终端”,然后输入 man profiles
。
如果你的客户端电脑已注册使用“移动设备管理”(MDM),则可恢复使用基于密码的认证。要实现这一点,请从客户端电脑中移除启用了仅智能卡限制的智能卡配置描述文件。
为防止用户的帐户被锁定,请在取消配对智能卡或停用属性匹配功能之前先移除 enforceSmartCard 描述文件。如果用户的帐户被锁定,请移除配置描述文件以解决这个问题。
如果你在启用仅智能卡认证之前已应用仅智能卡策略,则用户的电脑可能会被锁定。要解决这个问题,请移除仅智能卡策略:
开启 Mac,然后立即按住 Command-R 键,以便从 macOS 恢复功能启动。看到 Apple 标志、旋转的地球或要求输入固件密码的提示时,请松开这些按键。
从“实用工具”窗口中选择“磁盘工具”,然后点按“继续”。
在“磁盘工具”边栏中,选择你正在使用的宗卷,然后从菜单栏中选取“文件”>“装载”。(如果宗卷已装载,则这个选项呈暗灰色。)然后在系统提示时,输入你的管理员密码。
退出“磁盘工具”。
从菜单栏上的“实用工具”菜单中,选取“终端”。
删除配置描述文件储存库。要实现这一点,请打开“终端”,然后输入以下命令。
在这些命令中,请将 替换为已安装了描述文件设置的 macOS 宗卷的名称。
rm /Volumes//var/db/ConfigurationProfiles/MDM_ComputerPrefs.plist
rm /Volumes//var/db/ConfigurationProfiles/.profilesAreInstalled
rm /Volumes//var/db/ConfigurationProfiles/Settings/.profilesAreInstalled
rm /Volumes//var/db/ConfigurationProfiles/Store/ConfigProfiles.binary
rm /Volumes//var/db/ConfigurationProfiles/Setup/.profileSetupDone
完成后,请选取苹果 () 菜单 >“重新启动”。
重新安装在你启用仅智能卡认证之前就已存在的配置描述文件。
配置 Secure Shell 监控程序 (SSHD) 以支持仅智能卡认证
用户可以使用智能卡,通过 SSH 对本地电脑或已正确配置的远程电脑进行认证。请按照以下步骤在电脑上配置 SSHD,以支持智能卡认证。
更新 /etc/ssh/sshd_config 文件:
使用以下命令备份 sshd_config 文件:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup_`date "+%Y-%m-%d_%H:%M"`
在 sshd_config 文件中,将“#ChallengeResponseAuthentication yes”更改为“ChallengeResponseAuthentication no”,并将“#PasswordAuthentication yes”更改为“#PasswordAuthentication no”。
然后,使用以下命令重新启动 SSHD:
sudo launchctl stop com.openssh.sshd
sudo launchctl start com.openssh.sshd
如果用户想要使用智能卡来认证 SSH 会话,请让他们按照以下步骤操作:
使用以下命令从他们的智能卡中导出公共密钥:
ssh-keygen -D /usr/lib/ssh-keychain.dylib
将上一步中的公共密钥添加到目标电脑上的 ~/.ssh/authorized_keys 文件中。
使用以下命令备份 ssh_config 文件:
sudo cp /etc/ssh/ssh_config /etc/ssh/ssh_config_backup_`date "+%Y-%m-%d_%H:%M"`
在 /etc/ssh/ssh_config 文件中,添加行“PKCS11Provider=/usr/lib/ssh-keychain.dylib”。
如果用户愿意,他们还可以使用以下命令将专用密钥添加到 ssh-agent 中:
ssh-add -s /usr/lib/ssh-keychain.dylib
为 SUDO 命令启用仅智能卡认证
请使用以下命令备份 /etc/pam.d/sudo 文件:
sudo cp /etc/pam.d/sudo /etc/pam.d/sudo_backup_`date "+%Y-%m-%d_%H:%M"`
然后,将 /etc/pam.d/sudo 文件中的所有内容替换成以下文本:
# sudo: auth account password session auth sufficient pam_smartcard.so auth required pam_opendirectory.so auth required pam_deny.so account required pam_permit.so password required pam_deny.so session required pam_permit.so
为 LOGIN 命令启用仅智能卡认证
请使用以下命令备份 /etc/pam.d/login 文件:
sudo cp /etc/pam.d/login /etc/pam.d/login_backup_`date "+%Y-%m-%d_%H:%M"`
然后,将 /etc/pam.d/login 文件中的所有内容替换成以下文本:
# login: auth account password session auth sufficient pam_smartcard.so auth optional pam_krb5.so use_kcminit auth optional pam_ntlm.so try_first_pass auth optional pam_mount.so try_first_pass auth required pam_opendirectory.so try_first_pass auth required pam_deny.so account required pam_nologin.so account required pam_opendirectory.so password required pam_opendirectory.so session required pam_launchd.so session required pam_uwtmp.so session optional pam_mount.so
为 SU 命令启用仅智能卡认证
请使用以下命令备份 /etc/pam.d/su 文件:
sudo cp /etc/pam.d/su /etc/pam.d/su_backup_`date "+%Y-%m-%d_%H:%M"`
然后,将 /etc/pam.d/su 文件中的所有内容替换成以下文本:
# su: auth account password session auth sufficient pam_smartcard.so auth required pam_rootok.so auth required pam_group.so no_warn group=admin,wheel ruser root_only fail_safe account required pam_permit.so account required pam_opendirectory.so no_check_shell password required pam_opendirectory.so session required pam_launchd.so
仅智能卡配置描述文件示例
以下是仅智能卡配置描述文件的示例。你可以通过这个示例来了解这类描述文件包含哪些类型的密钥和字符串。
PayloadContent PayloadDescription Configures smart card-only PayloadDisplayName Smart card-only PayloadIdentifier com.apple.configprofile.78. PayloadOrganization Apple PayloadType com.apple.security.smartcard PayloadUUID 5A15247B-899C-474D-B1D7-DBD82BDE5678 PayloadVersion 1 UserPairing allowSmartCard checkCertificateTrust enforceSmartCard PayloadDescription Smartcard profile. PayloadDisplayName Smart card-only PayloadIdentifier com.apple.configprofile.77 PayloadOrganization PayloadRemovalDisallowed PayloadType Configuration PayloadScope system PayloadUUID 7D34CC86-C707-44D2-9A9F-C5F6E347BD77 PayloadVersion 1