尝试设置 2fa 但登录时从未提示

尝试设置 2fa 但登录时从未提示

这是我第一次在这里发帖,所以请耐心等待。我目前正在尝试使用本指南在我的 ubuntu 20.04 服务器上设置 2fa:https://ubuntu.com/tutorials/configure-ssh-2fa#1-overview

但是,按照所有步骤操作后,我填写密码后从未提示我输入验证码,只是登录即可。但是,当我把它放在@include common-auth 前面时,它会先要求我输入验证码,然后再输入密码。

我目前不知道如何解决这个问题,所以如果有人知道解决方案或有任何有用的指点,我很乐意听到!

我的 /etc/pam.d/sshd 文件:

  GNU nano 4.8               /etc/pam.d/sshd                          
# PAM configuration for the Secure Shell service
#auth required pam_google_authenticator.so
# Standard Un*x authentication.
@include common-auth
auth required pam_google_authenticator.so


# 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 com>
# 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 th>
# module could execute code in the wrong domain.
session [success=ok ignore=ignore module_unknown=ignore default=bad] >

# 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 mov>
# /etc/default/locale, so read that as well.
session    required     pam_env.so user_readenv=1 envfile=/etc/defaul>

# SELinux needs to intervene at login time to ensure that the process># in the proper default security context.  Only sessions which are in>
# to run in the user's context should be run after this.
session [success=ok ignore=ignore module_unknown=ignore default=bad] >

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

我的 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 wi>
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override t>
# default value.

Include /etc/ssh/sshd_config.d/*.conf

Port 18222
#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 VERBOSE

# Authentication:

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
MaxAuthTries 3
MaxSessions 2

#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>
#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>
# 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

AllowAgentForwarding no
AllowTcpForwarding no
#GatewayPorts no
X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
TCPKeepAlive no
PermitUserEnvironment no
#Compression delayed
ClientAliveInterval 0
ClientAliveCountMax 2
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
#Match group sftp
#ChrootDirectory /home
#X11Forwarding no
#AllowTcpForwarding no
#ForceCommand internal-sftp

相关内容