Score:0

SSH won't ask for 2FA code

tc flag

I'm trying to confiugre SSH 2FA on a Debian 11 server with Google Authenticator.

I have password login disabled,only publickey-login is allowed.

I already followed this and this guide, but without success.

The fact is, that when I try to connect to my server, it doesn't ask for the 2fa code, but just for the public key's password.

I also found out that, for some reasons, when I put AuthenticatioMethods publickey,keyboard-interactivein /etc/ssh/sshd_confing, keyboard-interactive acts like password, and asks for the user's password instead of Google Authenticator code. Here's my /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

And here's my /etc/pam.d/sshd

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

This is ssh -v output:

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: 

That "Password" is where I'm stuck.

Does anyone know how to fix this?

asktyagi avatar
in flag
Are you sure you have followed all steps? I can see discrepancy between your config and docs which you are following.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.