The problem is that the server keeps asking for serveruser password on login after the public key was sent and accepted.
well, you specifically asked for it.
AuthenticationMethods publickey,keyboard-interactive
Quoting sshd_config
manual,
AuthenticationMethods
Specifies the authentication methods that must be successfully completed for a user to be granted access. ... by the single string any
to indicate the default behaviour of accepting any single authentication method ...
... For example, "publickey,password publickey,keyboard-interactive" would require the user to complete public key authentication, followed by either password or keyboard interactive authentication. ...
So, adding AuthenticationMethods publickey,keyboard-interactive
to your sshd_config
, means you expect to have publickey
authentication completed first, then keyboard-interactive
authentication completed next.
If you expect to only authenticate with publickey
, probably change
AuthenticationMethods publickey,keyboard-interactive
to
AuthenticationMethods publickey
or, if you enable any other authentication methods and expect any single successful authentication method as an OK, you may use
AuthenticationMethods any
I want to authenticate both with public key and 2FA
You may want to disable common-auth
from PAM configs, as in most Linux/Unix distributions, common-auth
includes pam-unix.so
or pam-unix2.so
which requires account password.