需要有關 ubuntu 上的 google 身份驗證器的協助

需要有關 ubuntu 上的 google 身份驗證器的協助

我有 Ubuntu 20.04.3 LTS,我已經成功安裝了用於 MFA 身份驗證的 Google 身份驗證器,現在我需要有關身份驗證步驟的幫助,我的目標是:

  1. 如果使用者沒有 ssh 金鑰,則在 SSH 連線上,使用者必須先輸入密碼,然後輸入 Google 驗證金鑰才能存取系統。

  2. 如果使用者有 ssh 金鑰,則無需輸入密碼,但需要輸入 Google 驗證金鑰。

這是否可能,如果是,我需要設定什麼樣的設定/etc/ssh/sshd_config以及/etc/pam.d/sshd

這是我現有的/etc/pam.d/sshd配置

# Standard Un*x password updating.
@include common-password

# Standard Un*x authentication.
@include common-auth

# Standard Un*x authentication.
auth required pam_google_authenticator.so nullok user=root secret=/root/totp/${USER}
auth required pam_permit.so

這是/etc/ssh/sshd_config文件

ChallengeResponseAuthentication yes
UsePAM yes
PubkeyAuthentication yes
AuthorizedKeysFile     .ssh/authorized_keys
PermitRootLogin yes
PasswordAuthentication no
AuthenticationMethods publickey,keyboard-interactive

答案1

假設您已正確安裝所有內容,即安裝了:

sudo apt-get install libpam-google-authenticator

並得到了一個代碼

google-authenticator

您的主資料夾中有一個程式碼

ls /home/$USER/.google_authenticator

然後您應該將以下兩行添加到您的 /etc/pam.d/sshd

...

# Standard Un*x password updating.
@include common-password
auth required pam_google_authenticator.so
auth required pam_permit.so

...

或者,如果您希望 MFA 對某些用戶來說是可選的

...

# Standard Un*x password updating.
@include common-password
auth required pam_google_authenticator.so nullok
auth required pam_permit.so

...

在 /etc/ssh/sshd_config 檔案中更改:

ChallengeResponseAuthentication yes

然後:

sudo systemctl restart sshd.service

測試時不要終止你的 ssh 連接開始一個新的,如果你的配置錯誤你可能會被鎖定

答案2

KbdInteractiveAuthenticationin/etc/ssh/sshd_config也很重要,
用ubuntu 22.04測試過

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
#   KbdInteractiveAuthentication no
KbdInteractiveAuthentication yes

相關內容