所以,我想要的是使用 Yubikey 作为第二因素或唯一因素登录系统。
我使用 Linux Mint 21.3,我的 Yubikey 是 5C NFC。
我的/etc/pam.d/common-auth
:
auth [success=1 default=ignore] pam_unix.so nullok
auth requisite pam_deny.so
auth required pam_oath.so debug usersfile=/etc/users.oath digits=6 window=0
auth required pam_permit.so
auth required pam_ecryptfs.so unwrap
auth optional pam_cap.so
我唯一添加的是第三行,其余的在我之前就已经存在了。
Q1:
我理解的是否正确?行顺序很重要?
我oathtool
生成并将 HEX 密钥转换为 Base32 密钥:
kein@leaf:~$ oathtool -v --hotp -d 6 46362175108032033577
Hex secret: 46362175108032033577
Base32 secret: IY3CC5IQQAZAGNLX
Digits: 6
Window size: 0
Start counter: 0x0 (0)
801904
使用yubikey-manager
(1.2.5 AppImage),我将其中一个插槽配置为OATH-HOTP
粘贴 Base32 机密并选择 6 位数字。
然后我创建/etc/users.oath
:(600 权限,所有者 - root)
HOTP kein - 46362175108032033577
现在:第一次尝试成功:
kein@leaf:~$ sudo echo "YAPPY"
[sudo] password for kein:
[../../pam_oath/pam_oath.c:parse_cfg(123)] called.
[../../pam_oath/pam_oath.c:parse_cfg(124)] flags 32768 argc 4
[../../pam_oath/pam_oath.c:parse_cfg(126)] argv[0]=debug
[../../pam_oath/pam_oath.c:parse_cfg(126)] argv[1]=usersfile=/etc/users.oath
[../../pam_oath/pam_oath.c:parse_cfg(126)] argv[2]=digits=6
[../../pam_oath/pam_oath.c:parse_cfg(126)] argv[3]=window=0
[../../pam_oath/pam_oath.c:parse_cfg(127)] debug=1
[../../pam_oath/pam_oath.c:parse_cfg(128)] alwaysok=0
[../../pam_oath/pam_oath.c:parse_cfg(129)] try_first_pass=0
[../../pam_oath/pam_oath.c:parse_cfg(130)] use_first_pass=0
[../../pam_oath/pam_oath.c:parse_cfg(131)] usersfile=/etc/users.oath
[../../pam_oath/pam_oath.c:parse_cfg(132)] digits=6
[../../pam_oath/pam_oath.c:parse_cfg(133)] window=0
[../../pam_oath/pam_oath.c:pam_sm_authenticate(275)] get user returned: kein
[../../pam_oath/pam_oath.c:pam_sm_authenticate(283)] usersfile is /etc/users.oath
[../../pam_oath/pam_oath.c:pam_sm_authenticate(293)] authenticate first pass rc -2 (OATH_INVALID_DIGITS: Unsupported number of OTP digits) last otp Sun Jun 30 07:11:28 3357022
One-time password (OATH) for `kein':
[../../pam_oath/pam_oath.c:pam_sm_authenticate(376)] conv returned: 801904
[../../pam_oath/pam_oath.c:pam_sm_authenticate(440)] OTP: 801904
[../../pam_oath/pam_oath.c:pam_sm_authenticate(448)] authenticate rc 0 (OATH_OK: Successful return) last otp Tue Nov 8 02:59:37 4368416
[../../pam_oath/pam_oath.c:pam_sm_authenticate(472)] done. [Success]
YAPPY
但第二次尝试(另一个终端)失败了:
kein@leaf:~$ sudo echo "YAPPY"
[sudo] password for kein:
[../../pam_oath/pam_oath.c:parse_cfg(123)] called.
[../../pam_oath/pam_oath.c:parse_cfg(124)] flags 32768 argc 4
[../../pam_oath/pam_oath.c:parse_cfg(126)] argv[0]=debug
[../../pam_oath/pam_oath.c:parse_cfg(126)] argv[1]=usersfile=/etc/users.oath
[../../pam_oath/pam_oath.c:parse_cfg(126)] argv[2]=digits=6
[../../pam_oath/pam_oath.c:parse_cfg(126)] argv[3]=window=0
[../../pam_oath/pam_oath.c:parse_cfg(127)] debug=1
[../../pam_oath/pam_oath.c:parse_cfg(128)] alwaysok=0
[../../pam_oath/pam_oath.c:parse_cfg(129)] try_first_pass=0
[../../pam_oath/pam_oath.c:parse_cfg(130)] use_first_pass=0
[../../pam_oath/pam_oath.c:parse_cfg(131)] usersfile=/etc/users.oath
[../../pam_oath/pam_oath.c:parse_cfg(132)] digits=6
[../../pam_oath/pam_oath.c:parse_cfg(133)] window=0
[../../pam_oath/pam_oath.c:pam_sm_authenticate(275)] get user returned: kein
[../../pam_oath/pam_oath.c:pam_sm_authenticate(283)] usersfile is /etc/users.oath
[../../pam_oath/pam_oath.c:pam_sm_authenticate(293)] authenticate first pass rc -2 (OATH_INVALID_DIGITS: Unsupported number of OTP digits) last otp Sun Mar 24 18:24:03 2024
One-time password (OATH) for `kein':
[../../pam_oath/pam_oath.c:pam_sm_authenticate(376)] conv returned: 118838
[../../pam_oath/pam_oath.c:pam_sm_authenticate(440)] OTP: 118838
[../../pam_oath/pam_oath.c:pam_sm_authenticate(448)] authenticate rc -6 (OATH_INVALID_OTP: The OTP is not valid) last otp Sun Mar 24 18:24:03 2024
[../../pam_oath/pam_oath.c:pam_sm_authenticate(455)] One-time password not authorized to login as user 'kein'
[../../pam_oath/pam_oath.c:pam_sm_authenticate(472)] done. [Authentication failure]
Sorry, try again.
[sudo] password for kein:
毕竟/etc/users.oath
包含:HOTP kein - 46362175108032033577 0 801904 2024-03-24T18:24:03L
2Q
:为什么第二次(以及后续)尝试失败?出了什么问题?
3Q
: 为什么OATH_INVALID_DIGITS: Unsupported number of OTP digits
?