skip to content

An OpenSSH server has PasswordAuthentication no, yet clients still get a password prompt; which sshd_config settings explain it, and what do you set?

level: middleimportance: must knowfreq 52%

answer

  1. two methods can ask for a password
  2. keyboard-interactive is a separate switch
  3. PAM speaks through keyboard-interactive
  4. first obtained value wins
  5. Match blocks override the global section

basics

~20 s

PasswordAuthentication covers only the password method; keyboard-interactive is separate, defaults to yes, and with UsePAM yes PAM asks for the password through it. Set KbdInteractiveAuthentication no too, then check Include files and Match blocks for an overriding yes.

solid answer

~40 s

SSH user authentication has a `password` method (RFC 4252) and, separately, `keyboard-interactive` (RFC 4256), a generic prompt-and-answer method. `PasswordAuthentication no` switches off only the first. `KbdInteractiveAuthentication` defaults to `yes`, and with `UsePAM yes` PAM authenticates through it, so the PAM stack asks for the account password and the user sees an ordinary prompt. Set `KbdInteractiveAuthentication no` as well (`ChallengeResponseAuthentication` is its deprecated alias). If a prompt survives, look for a value obtained earlier or a scoped override: sshd keeps the first value it reads for most keywords, so an `Include`d drop-in at the top of the file beats a later line, and a satisfied `Match` block overrides the global setting. Finally, rule out the client asking for its own key's passphrase, which is local and not a server login.

code

ini · 10 lines
ini
# /etc/ssh/sshd_config (excerpt)
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
UsePAM yes

# Match blocks go last: each runs to the next Match line or the end of the file
Match Address 198.51.100.0/24
    PasswordAuthentication yes
    KbdInteractiveAuthentication yes

go deeper

for a junior

Recall the lines for key-only logins: PasswordAuthentication no and KbdInteractiveAuthentication no, with keys in place first. Know that keyboard-interactive can ask for a password too.

for a middle

Explain the two RFC methods, how UsePAM routes PAM through keyboard-interactive, and why the documented setup keeps UsePAM yes with both password-capable switches off.

for a senior

Diagnose a surviving prompt systematically: first-obtained values from Include files, Match overrides, the effective configuration, and the client's own key passphrase prompt.

for a principal

Treat no passwords as a rollout: every account needs a key or certificate before the switch, exceptions live in narrow Match blocks, and audits read the effective configuration, not one file.

## Two methods can collect a password SSH user authentication is a menu of **methods**. RFC 4252 defines `publickey`, `password` and `hostbased` (plus `none`); RFC 4256 adds **`keyboard-interactive`**, in which the server sends one or more prompts, the client displays them, and the user types answers. The prompts can say anything: "Password:", a one-time code, both. From the user's chair a keyboard-interactive password prompt looks much like the password method. Each method has its own switch in OpenSSH's `sshd_config`: | Directive | Method it controls | Default in 10.5 | |---|---|---| | `PasswordAuthentication` | `password` (RFC 4252) | `yes` | | `KbdInteractiveAuthentication` | `keyboard-interactive` (RFC 4256) | `yes` | | `PubkeyAuthentication` | `publickey` | `yes` | | `UsePAM` | whether PAM backs password and keyboard-interactive, plus PAM account and session processing | `no` upstream | `ChallengeResponseAuthentication` is a **deprecated alias** of `KbdInteractiveAuthentication`; since OpenSSH 8.7 the documentation uses the RFC 4256 name, and the old one still works in existing files. ## Where PAM comes in With `UsePAM yes`, sshd_config(5) says PAM authentication is enabled through both `KbdInteractiveAuthentication` and `PasswordAuthentication`, and it advises disabling one of them because PAM keyboard-interactive "usually serves an equivalent role to password authentication". So the classic sequence is: 1. The administrator sets `PasswordAuthentication no`. 2. `KbdInteractiveAuthentication` is still at its default, `yes`. 3. `UsePAM yes` is set (upstream's default is `no`, but packaged configurations often turn it on, so read your own file). 4. The client falls through to keyboard-interactive, PAM asks for the account password, and a guessable secret is still accepted. The fix is **not** to turn PAM off. The shipped `sshd_config` explains the intended setup: if you want PAM's account and session checks without PAM authentication, enable `UsePAM` but set both `PasswordAuthentication` and `KbdInteractiveAuthentication` to `no`. ```ini # Key-only logins for shell users, PAM account and session checks kept PubkeyAuthentication yes PasswordAuthentication no KbdInteractiveAuthentication no UsePAM yes ``` ## When the prompt still appears If both switches say `no` in the file you edited and a prompt remains, the value sshd actually uses is coming from somewhere else: - **An earlier `Include`.** sshd_config(5): "Unless noted otherwise, for each keyword, the first obtained value will be used." `Include` expands its glob in lexical order at the point where it appears, so a drop-in file included near the top that says `PasswordAuthentication yes` wins over a `no` further down the main file. - **A `Match` block.** `PasswordAuthentication` and `KbdInteractiveAuthentication` are both allowed inside `Match`. A satisfied `Match User` or `Match Address` block overrides the global value for that connection, so one forgotten block can reopen passwords for a subnet or a user. - **The daemon has not loaded the change.** Checking a configuration and reloading sshd safely belongs to the material on OpenSSH operations; for this question it is enough that `sshd -T` prints the effective values, and its `-C` option evaluates `Match` rules for given connection parameters. - **It is not a server prompt at all.** "Enter passphrase for key" comes from the client unlocking its own encrypted private key. It proves nothing about the server accepting passwords. ## What switching passwords off buys - Password guessing against the server can no longer succeed, however many attempts arrive; the log noise remains, but it is harmless noise. - Every account must already have a key or certificate before the switch, otherwise people are locked out; inventory first. - Exceptions are explicit and narrow: a `Match Address` block for an internal range, rather than a global `yes`. - What each remaining method proves, and how to require two methods together, is a question about authentication methods rather than about switching them off. ## Why keyboard-interactive exists at all Keyboard-interactive was designed for authentication that is not a single static password: one-time codes, challenge-response tokens, or several prompts in sequence. That is why it is a separate method with its own switch, and why switching it off removes every prompt PAM would have shown, second-factor prompts included. If some accounts need a key plus a one-time code, that is a design question about combining authentication methods, not a reason to leave keyboard-interactive on for everyone; decide it explicitly rather than inheriting it from a default. ## The interview answer in one line Two methods can ask for a password, PAM speaks through the second one, and sshd keeps the first value it reads, so check `KbdInteractiveAuthentication`, includes and `Match` blocks before blaming the client.

  • Why does the documented key-only setup keep UsePAM yes instead of turning PAM off?
    PAM does more than check passwords: with `UsePAM yes`, sshd also runs PAM account and session processing for every authentication type, such as account expiry and session setup. The shipped `sshd_config` says to keep those by enabling `UsePAM` while setting `PasswordAuthentication` and `KbdInteractiveAuthentication` to `no`, which removes PAM's password prompt only.
  • Can you allow passwords from one internal network while keeping them off from the internet?
    Yes. Keep both switches `no` in the global section, then add a `Match Address` block for the internal range, for example 198.51.100.0/24, that sets them to `yes`. Both keywords are allowed inside `Match`, and a satisfied block overrides the global value for that connection only.
  • A drop-in file and the main sshd_config disagree about PasswordAuthentication. Which value wins?
    For most keywords sshd keeps the first value it obtains. If the main file starts with an `Include` of a drop-in directory, those files are read at that point in lexical order, so a drop-in's value is obtained first and wins over any later line. `sshd -T` shows the value actually in force.

  • PasswordAuthentication no turns off every way of typing a password.
  • ChallengeResponseAuthentication and KbdInteractiveAuthentication are two independent switches.
  • UsePAM must be no on a key-only server.
  • The last PasswordAuthentication line in sshd_config always wins.
  • An 'Enter passphrase for key' prompt shows the server still accepts passwords.

Assumes OpenSSH 10.5: PasswordAuthentication and KbdInteractiveAuthentication default to yes and UsePAM to no; ChallengeResponseAuthentication has been a deprecated alias since 8.7.