我正在嘗試配置我的 SSHD 以使用 FreeRadius 對使用者進行身份驗證。 FreeRadius 伺服器需要先使用 Google Authenticator 要求有效的 OTP,然後再驗證系統帳號密碼。
如果我將 Radius 伺服器設定為僅有的使用Google Authenticator,但是當我新增詢問系統帳戶密碼的額外步驟時,Google Authenticator令牌每次都會失敗。我認為我的問題是我的 PAM 配置,但我不明白我做錯了什麼。
我將運行 SSHD 的伺服器稱為「客戶端」伺服器,將 FreeRadius 伺服器稱為「radius」伺服器。
這是我的客戶端:/etc/pam.d/sshd
#%PAM-1.0
auth required pam_sepermit.so
auth required pam_radius_auth.so debug prompt=token
#auth include password-auth
auth include postlogin
account required pam_nologin.so
account include password-auth
account sufficient pam_radius_auth.so
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 optional pam_keyinit.so force revoke
session include password-auth
session include postlogin
我還在客戶端中啟用了質詢/回應身份驗證:/etc/ssh/sshd_config,其中包含以下行:
ChallengeResponseAuthentication yes
這是我在 Radius 伺服器上的 /etc/pam.d/radiusd 設定:
#%PAM-1.0
auth requisite pam_google_authenticator.so
auth include password-auth
account required pam_nologin.so
account include password-auth
password include password-auth
session include password-auth
#@include common-auth
#@include common-account
#@include common-password
#@include common-session
為了讓您能夠追蹤鏈,這裡是 Radius 伺服器上的 /etc/pam.d/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 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
其運作方式是,客戶端伺服器只需要 Radius 伺服器接受即可接受登錄,但 Radius 伺服器需要帶有 GoogleAuthenticator 的 OTP 和本機 pam_unix 密碼才能接受。這就是我要的。
奇怪的是,當我註解掉 radius 伺服器 /etc/pam.d/radiusd 檔案中的行時:
auth include password-auth
然後我可以登入客戶端伺服器,它會提示我輸入我的 GoogleAuthenticator 令牌。當我這樣做時一切正常。我從手機獲得的 OTP 被接受,請求被發送到 radius,它返回到客戶端伺服器,並讓我進入。
但如果取消註解上面的行,系統會要求我提供 GoogleAuthenticator 令牌,並且每次輸入它時都會失敗。奇怪的是,它要求我提供 OTP 令牌 4 次,然後要求我提供系統帳戶密碼,然後說失敗。誰能幫我讓它運作嗎?
這是我嘗試使用時“radiusd -X”的調試輸出兩個都GoogleAuthenticator 令牌和 unix 密碼:
Received Access-Request Id 112 from client:48253 to radius:1812 length 94
User-Name = ‘bob’
User-Password = '146963'
NAS-IP-Address = client
NAS-Identifier = 'sshd'
NAS-Port = 9148
NAS-Port-Type = Virtual
Service-Type = Authenticate-Only
Calling-Station-Id = ‘xxx.xxx.xxx.xxx’
(0) Received Access-Request packet from host 192.168.20.51 port 48253, id=112, length=94
(0) User-Name = ‘bob’
(0) User-Password = '146963'
(0) NAS-IP-Address = xxx.xxx.xxx.xxx
(0) NAS-Identifier = 'sshd'
(0) NAS-Port = 9148
(0) NAS-Port-Type = Virtual
(0) Service-Type = Authenticate-Only
(0) Calling-Station-Id = ‘xxx.xxx.xxx.xxx’
(0) # Executing section authorize from file /etc/raddb/sites-enabled/default
(0) authorize {
(0) filter_username filter_username {
(0) if (!&User-Name)
(0) if (!&User-Name) -> FALSE
(0) if (&User-Name =~ / /)
(0) if (&User-Name =~ / /) -> FALSE
(0) if (&User-Name =~ /@.*@/ )
(0) if (&User-Name =~ /@.*@/ ) -> FALSE
(0) if (&User-Name =~ /\\.\\./ )
(0) if (&User-Name =~ /\\.\\./ ) -> FALSE
(0) if ((&User-Name =~ /@/) && (&User-Name !~ /@(.+)\\.(.+)$/))
(0) if ((&User-Name =~ /@/) && (&User-Name !~ /@(.+)\\.(.+)$/)) -> FALSE
(0) if (&User-Name =~ /\\.$/)
(0) if (&User-Name =~ /\\.$/) -> FALSE
(0) if (&User-Name =~ /@\\./)
(0) if (&User-Name =~ /@\\./) -> FALSE
(0) } # filter_username filter_username = notfound
(0) [preprocess] = ok
(0) [chap] = noop
(0) [mschap] = noop
(0) [digest] = noop
(0) suffix : Checking for suffix after "@"
(0) suffix : No '@' in User-Name = “bob”, looking up realm NULL
(0) suffix : No such realm "NULL"
(0) [suffix] = noop
(0) eap : No EAP-Message, not doing EAP
(0) [eap] = noop
(0) files : users: Matched entry DEFAULT at line 198
(0) [files] = ok
(0) [expiration] = noop
(0) [logintime] = noop
(0) WARNING: pap : No "known good" password found for the user. Not setting Auth-Type
(0) WARNING: pap : Authentication will fail unless a "known good" password is available
(0) [pap] = noop
(0) } # authorize = ok
(0) Found Auth-Type = PAM
(0) # Executing group from file /etc/raddb/sites-enabled/default
(0) authenticate {
pam_pass: using pamauth string <radiusd> for pam.conf lookup
pam_pass: function pam_authenticate FAILED for <bob>. Reason: Authentication failure
(0) [pam] = reject
(0) } # authenticate = reject
(0) Failed to authenticate the user
(0) Using Post-Auth-Type Reject
(0) # Executing group from file /etc/raddb/sites-enabled/default
(0) Post-Auth-Type REJECT {
(0) attr_filter.access_reject : EXPAND %{User-Name}
(0) attr_filter.access_reject : --> bob
(0) attr_filter.access_reject : Matched entry DEFAULT at line 11
(0) [attr_filter.access_reject] = updated
(0) eap : Request didn't contain an EAP-Message, not inserting EAP-Failure
(0) [eap] = noop
(0) remove_reply_message_if_eap remove_reply_message_if_eap {
(0) if (&reply:EAP-Message && &reply:Reply-Message)
(0) if (&reply:EAP-Message && &reply:Reply-Message) -> FALSE
(0) else else {
(0) [noop] = noop
(0) } # else else = noop
(0) } # remove_reply_message_if_eap remove_reply_message_if_eap = noop
(0) } # Post-Auth-Type REJECT = updated
(0) Delaying response for 1 seconds
Waking up in 0.9 seconds.
(0) Sending delayed response
(0) Sending Access-Reject packet to host xxx.xxx.xxx.xxx port 48253, id=112, length=0
Sending Access-Reject Id 112 from xxx.xxx.xxx.xxx:1812 to xxx.xxx.xxx.xxx:48253
Waking up in 3.9 seconds.
(0) Cleaning up request packet ID 112 with timestamp +20
Ready to process requests
Received Access-Request Id 81 from xxx.xxx.xxx.xxx:45486 to xxx.xxx.xxx.xxx:1812 length 94
User-Name = ’bob’
User-Password = '146963'
NAS-IP-Address = xxx.xxx.xxx.xxx
NAS-Identifier = 'sshd'
NAS-Port = 9149
NAS-Port-Type = Virtual
Service-Type = Authenticate-Only
Calling-Station-Id = ‘xxx.xxx.xxx.xxx’
答案1
我想到了。問題出在 /etc/pam.d/password-auth 檔案的 PAM 堆疊中。具體來說這一行:
auth sufficient pam_unix.so nullok try_first_pass
發生的情況是 google-authenticator 的令牌被接受,但由於「try_first_pass」選項,pam_unix.so 嘗試使用該代碼作為系統密碼。我不知道為什麼,但這導致整個身份驗證鏈重新開始,要求輸入 google-auth 密碼。
擺脫“try_first_pass”選項可以解決問題並為我提供所需的行為。