brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: AuthenticationMethods makes sshd ask for a key and a password

Network and access
~/tips/tip-sshd-authenticationmethods

AuthenticationMethods publickey,password

Require two login steps, so a stolen key or a guessed password alone is not enough.

Normally SSH accepts one method: a key or a password. With AuthenticationMethods you can demand both, one after the other.

In sshd_config:

AuthenticationMethods publickey,password

A comma means “and then”. The user first passes with a key, then sshd asks for the password. A space separates alternatives, so this allows key plus password, or key plus keyboard-interactive (the usual way TOTP modules ask for a code):

AuthenticationMethods publickey,password publickey,keyboard-interactive

The methods you list must be switched on as well. With PasswordAuthentication no in the file, the password step can never succeed and nobody gets in, so check that setting too.

I would try it in a Match User block for one account first, and test with sudo sshd -t and a second terminal before closing the session you are in. Locking yourself out of a remote box this way is very easy.

Worth knowing: a key with a passphrase already asks for something you know, just on your own machine. This option is about the server checking both. It fits best when keys might live on machines you do not fully control.

Further reading: sshd_config man page

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link