SSH 2FA und RSA Key Ubuntu 20.04
Hallo,
ich wollte unter Ubuntu 20.04 neben dem RSA Key (funktioniert) eine 2FA einrichten.
Dazu habe ich diese Schritte durchgeführt
google-authenticator
-Do you want authentication tokens to be time-based (y/n) y
-Do you want me to update your "/home/roman/.google_authenticator" file? (y/n) y
-Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y
-By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) n
-If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) y
nano /etc/pam.d/sshd
#@include common-auth
And all the way on the bottom add
@include common-password
auth required pam_google_authenticator.so
nano /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
UsePAM yes
AuthenticationMethods publickey,keyboard-interactive
service ssh restart
Wenn ich mich jetzt anmelden will, meckert Putty: No supported authentication methods available (server sent: keyboard-interactive)
Was hab ich falsch gemacht?
Christian
Danke
ich wollte unter Ubuntu 20.04 neben dem RSA Key (funktioniert) eine 2FA einrichten.
Dazu habe ich diese Schritte durchgeführt
google-authenticator
-Do you want authentication tokens to be time-based (y/n) y
-Do you want me to update your "/home/roman/.google_authenticator" file? (y/n) y
-Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y
-By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) n
-If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) y
nano /etc/pam.d/sshd
#@include common-auth
And all the way on the bottom add
@include common-password
auth required pam_google_authenticator.so
nano /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
UsePAM yes
AuthenticationMethods publickey,keyboard-interactive
service ssh restart
Wenn ich mich jetzt anmelden will, meckert Putty: No supported authentication methods available (server sent: keyboard-interactive)
Was hab ich falsch gemacht?
Christian
Danke
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 662775
Url: https://administrator.de/forum/ssh-2fa-und-rsa-key-ubuntu-20-04-662775.html
Ausgedruckt am: 14.02.2025 um 19:02 Uhr
12 Kommentare
Neuester Kommentar

Falsch das bleibt dort drin.
setzen
And all the way on the bottom add
@include common-password
auth required pam_google_authenticator.so
Korrekt, nur die letzte Zeile hinzufügen die erste steht ja schon drin.@include common-password
auth required pam_google_authenticator.so
nano /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
OK.ChallengeResponseAuthentication yes
UsePAM yes
OKAuthenticationMethods publickey,keyboard-interactive
Das weg und nurPublicKeyAuthentication yes
setzen
service ssh restart
OKWenn ich mich jetzt anmelden will, meckert Putty: No supported authentication methods available (server sent: keyboard-interactive)
Klappt hier nach obiger Methode einwandfrei.
Zitat von @hokaido:
Danke. Es geht aber mit dem gleichen Ergebnis. So ging es vorher auch schon. Es kommt nur die Abfrage des SSH Key Passwortes.
Ich wollte aber SSH Key Passwort und 2FA.
Das ist normal,Danke. Es geht aber mit dem gleichen Ergebnis. So ging es vorher auch schon. Es kommt nur die Abfrage des SSH Key Passwortes.
Ich wollte aber SSH Key Passwort und 2FA.
Beides sind 2FA Methoden, bei der ersten ist das Passwort für den Key der zweite Schlüssel und bei letzterem das Token 😉.
Wenn du den privaten Schlüssel aus dem Verzeichnis raus nimmst fragt er dich dann automatisch nach Kennwort und auch nach dem Token.
Du hast in diesem Fall auch vergessen Passwort Authentication auf no zu setzen.

Zitat von @hokaido:
Danke. Vll. reden wir aneinander vorbei. Ich wollte - wenn es geht - dass beide Abfragen nacheinanderkommen. Erst die Eingabe des SSH Keys, dann die 2FA Abfrage.
Und das funktioniert eben so nicht. Vll. hab ich auch was falsch verstanden und es geht technisch nur ent- oder weder...
Das geht nur entweder oder. Wenn du das so haben willst musst du den privaten Key ohne Passwort versehen dann kommt zusätzlich die Verification Code Abfrage.Danke. Vll. reden wir aneinander vorbei. Ich wollte - wenn es geht - dass beide Abfragen nacheinanderkommen. Erst die Eingabe des SSH Keys, dann die 2FA Abfrage.
Und das funktioniert eben so nicht. Vll. hab ich auch was falsch verstanden und es geht technisch nur ent- oder weder...
Denn wie schon gesagt, beides sind 2FA Verfahren, das was du machen willst ist quasi 4FA.
Zitat von @147669:
Das geht nur entweder oder. Wenn du das so haben willst musst du den privaten Key ohne Passwort versehen dann kommt zusätzlich die Verification Code Abfrage.
ACHTUNG Falschinformation!Das geht nur entweder oder. Wenn du das so haben willst musst du den privaten Key ohne Passwort versehen dann kommt zusätzlich die Verification Code Abfrage.
Das gewünschte Verhalten ist problemlos realisierbar, genau dafür ist ja PAM so flexibel konfigurierbar
Halte dich exakt an die folgende Anleitung dann kommt das problemlos zum fliegen
https://www.digitalocean.com/community/tutorials/how-to-set-up-multi-fac ...
Die Anleitung ist zwar für Ubuntu 16.04, funktioniert aber exakt gleich auf einem 20.04 LTS! Wurde hier nochmal erfolgreich auf einer sauberen Ubuntu 20.04 LTS Server Version verifiziert. Das gleiche ist aber auch bswp. auf einem Debian und anderen Derivaten in ähnlicher Weise konfigurierbar, auch wenn man hier und da aufpassen muss wie die PAM Module verschachtelt sind.
Hier noch als Referenz meine genutzten Configs
/etc/pam.d/sshd
# PAM configuration for the Secure Shell service
# Standard Un*x authentication.
#@include common-auth
# Disallow non-root logins when /etc/nologin exists.
account required pam_nologin.so
# Uncomment and edit /etc/security/access.conf if you need to set complex
# access limits that are hard to express in sshd_config.
# account required pam_access.so
# Standard Un*x authorization.
@include common-account
# SELinux needs to be the first session rule. This ensures that any
# lingering context has been cleared. Without this it is possible that a
# module could execute code in the wrong domain.
session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so close
# Set the loginuid process attribute.
session required pam_loginuid.so
# Create a new session keyring.
session optional pam_keyinit.so force revoke
# Standard Un*x session setup and teardown.
@include common-session
# Print the message of the day upon successful login.
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session optional pam_motd.so motd=/run/motd.dynamic
session optional pam_motd.so noupdate
# Print the status of the user's mailbox upon successful login.
session optional pam_mail.so standard noenv # [1]
# Set up user limits from /etc/security/limits.conf.
session required pam_limits.so
# Read environment variables from /etc/environment and
# /etc/security/pam_env.conf.
session required pam_env.so # [1]
# In Debian 4.0 (etch), locale-related environment variables were moved to
# /etc/default/locale, so read that as well.
session required pam_env.so user_readenv=1 envfile=/etc/default/locale
# SELinux needs to intervene at login time to ensure that the process starts
# in the proper default security context. Only sessions which are intended
# to run in the user's context should be run after this.
session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so open
# Standard Un*x password updating.
@include common-password
auth required pam_google_authenticator.so
/etc/ssh/sshd_config/sshd
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
Include /etc/ssh/sshd_config.d/*.conf
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
AuthenticationMethods publickey,keyboard-interactive
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
#PasswordAuthentication yes
Grüße Uwe

Also, leider funktioniert das nicht, habe exakt deinen Code reinkopiert
Also das es offensichtlich geht siehst du ja am Bild von @colinardo oben 🐒. Hab das hier gerade nochmal nachgestellt und es geht tatsächlicheinwandfrei, musst du wohl falsche Settings im PuTTY gesetzt haben, oder dein System ist verbastelt.
/etc/ssh/sshd_config/sshd
Naja wenn du das da rein kopiert hat wundert das ehrlich gesagt nicht, die gibbet nämlich ned🙃Warte noch ein paar Minuten dann ist Freitag vorbei ...🐟