SSH 不会要求输入 2FA 代码

SSH 不会要求输入 2FA 代码

我正在尝试使用 Google Authenticator 在 Debian 11 服务器上配置 SSH 2FA。

我已禁用密码登录,只允许使用公钥登录。

我已经关注指导,但没有成功。

事实是,当我尝试连接到我的服务器时,它不会要求输入 2fa 代码,而只是要求输入公钥的密码。

我还发现,出于某些原因,当我输入 时AuthenticatioMethods publickey,keyboard-interactive/etc/ssh/sshd_confingkeyboard-interactive会像 一样运行password,并要求输入用户的密码而不是 Google Authenticator 代码。这是我的/etc/ssh/sshd_config

Include /etc/ssh/sshd_config.d/*.conf
Port 5566
MaxAuthTries 3
MaxSessions 2
PubkeyAuthentication yes
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication yes
UsePAM yes
AuthenticationMethods publickey,keyboard-interactive

这是我的/etc/pam.d/sshd

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

这是ssh -v输出:

lc@lc-ThinkPad-E550:~$ ssh -v -p 5566 [email protected]
OpenSSH_8.2p1 Ubuntu-4ubuntu0.7, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 192.168.43.240 [192.168.43.240] port 5566.
debug1: Connection established.
debug1: identity file /home/lc/.ssh/id_rsa type 0
debug1: identity file /home/lc/.ssh/id_rsa-cert type -1
debug1: identity file /home/lc/.ssh/id_dsa type -1
debug1: identity file /home/lc/.ssh/id_dsa-cert type -1
debug1: identity file /home/lc/.ssh/id_ecdsa type -1
debug1: identity file /home/lc/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/lc/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/lc/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/lc/.ssh/id_ed25519 type -1
debug1: identity file /home/lc/.ssh/id_ed25519-cert type -1
debug1: identity file /home/lc/.ssh/id_ed25519_sk type -1
debug1: identity file /home/lc/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/lc/.ssh/id_xmss type -1
debug1: identity file /home/lc/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.4p1 Debian-5+deb11u1
debug1: match: OpenSSH_8.4p1 Debian-5+deb11u1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.43.240:5566 as 'lc'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:V6k3rMQPjUN0z/IHqIGQLcu+qwcxUnG7t7UBNgVICdk
debug1: checking without port identifier
debug1: Host '192.168.43.240' is known and matches the ECDSA host key.
debug1: Found key in /home/lc/.ssh/known_hosts:1
debug1: found matching key w/out port
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/lc/.ssh/id_rsa RSA SHA256:g7Mg0E/en4eCckxoHso4aeJTNUrBrciEml+UEhc2kSE
debug1: Will attempt key: /home/lc/.ssh/id_dsa 
debug1: Will attempt key: /home/lc/.ssh/id_ecdsa 
debug1: Will attempt key: /home/lc/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/lc/.ssh/id_ed25519 
debug1: Will attempt key: /home/lc/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/lc/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/lc/.ssh/id_rsa RSA SHA256:g7Mg0E/en4eCckxoHso4aeJTNUrBrciEml+UEhc2kSE
debug1: Server accepts key: /home/lc/.ssh/id_rsa RSA SHA256:g7Mg0E/en4eCckxoHso4aeJTNUrBrciEml+UEhc2kSE
Enter passphrase for key '/home/lc/.ssh/id_rsa': 
Authenticated with partial success.
debug1: Authentications that can continue: keyboard-interactive
debug1: Next authentication method: keyboard-interactive
Password: 

那个“密码”就是我被困住的地方。

有谁知道如何解决这一问题?

相关内容