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に次の2行を追加します。

...

# 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

KbdInteractiveAuthentication/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

関連情報