Let PAM to provision users on their first login
Damien Miller
djm at mindrot.org
Fri Nov 20 07:01:38 AEDT 2026
On Wed, 18 Nov 2026, Marco Trevisan wrote:
> On each user login attempt, sshd looks the user up via NSS before
> authentication, and if the user does not exist it marks the login
> as invalid: the real password is replaced by a fake one, PAM success
> is treated as an internal error, and the login can never succeed.
>
> This prevents PAM modules that create the account as part of the
> authentication from working over SSH.
>
> In Ubuntu we have authd [1], which authenticates users against an
> identity provider (Entra ID, Google, ...) and creates the local
> account on first login; other services (directory or cloud identity
> integrations, on-demand provisioning on servers), relying on samba
> or SSSD have the same need.
>
> Today we've to work around this by making our NSS module report to sshd
> (only) users that do not exist yet when sshd asks, which is
> fragile and implies lots of logic to prevent the abuse of this feature.
>
> This series adds a PAMDeferUnknownUsers option (defaulting to yes).
> When it applies and the NSS lookup is a clear not-found, sshd
> lets the PAM keyboard-interactive conversation run, then
> re-checks the user in the monitor before the method is counted:
I don't love this because it fairly significantly complicates
some of the most critical code in OpenSSH.
If this were just reversing the order in which we call getpwnam() and
pam_start() then it wouldn't be so bad, but requiring sshd proceed with
an invalid account right up to the point of authentication success is
pretty scary.
The "monitor: Receive PAM account requests only after authentication"
bit is good though and mirrors a hardening that I've wanted to do for
a while.
-d
More information about the openssh-unix-dev
mailing list