Brauche Hilfe zum Google Authenticator auf Ubuntu

Brauche Hilfe zum Google Authenticator auf Ubuntu

Ich habe Ubuntu 20.04.3 LTS, wo ich Google Authenticator für die MFA-Authentifizierung erfolgreich installiert habe. Jetzt brauche ich Hilfe bei den Authentifizierungsschritten. Mein Ziel ist folgendes:

  1. Wenn ein Benutzer keinen SSH-Schlüssel hat, muss er bei einer SSH-Verbindung zuerst sein Passwort und dann den Google-Bestätigungsschlüssel eingeben, um Systemzugriff zu erhalten.

  2. Wenn ein Benutzer über einen SSH-Schlüssel verfügt, muss er kein Kennwort eingeben, er muss jedoch den Google-Bestätigungsschlüssel eingeben.

Ist das möglich, wenn ja, welche Einstellungen muss ich vornehmen /etc/ssh/sshd_configund/etc/pam.d/sshd

Hier ist meine bestehende /etc/pam.d/sshdKonfiguration

# 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

Und hier ist /etc/ssh/sshd_configdie Datei

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

Antwort1

Vorausgesetzt, Sie haben alles richtig installiert, d. h. installiert mit:

sudo apt-get install libpam-google-authenticator

Und bekam einen Code mit

google-authenticator

Und es gibt einen Code in Ihrem Home-Ordner unter

ls /home/$USER/.google_authenticator

Dann sollten Sie die folgenden beiden Zeilen zu Ihrer /etc/pam.d/sshd hinzufügen

...

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

...

Oder wenn Sie möchten, dass MFA für einige Benutzer optional ist

...

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

...

Ändern Sie in Ihrer Datei /etc/ssh/sshd_config:

ChallengeResponseAuthentication yes

Dann:

sudo systemctl restart sshd.service

Unterbrechen Sie beim Testen nicht Ihre SSH-VerbindungStarten Sie ein neues. Wenn Ihre Konfiguration falsch ist, können Sie ausgesperrt werden

Antwort2

KbdInteractiveAuthenticationin /etc/ssh/sshd_configist auch sehr wichtig,
getestet mit Ubuntu 22.04

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

verwandte Informationen