Let PAM to provision users on their first login
Marco Trevisan
marco at ubuntu.com
Thu Nov 19 10:43:16 AEDT 2026
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:
- the user must exist and pass the usual checks (AllowUsers, root
policy, RefuseConnection, ...) once PAM has succeeded;
- Match is re-evaluated for the real user; if the effective
configuration differs from the one used for authentication so far
(e.g. a Match Group selects another PAMServiceName or other
AuthenticationMethods), the connection is refused and the client has
to reconnect, rather than switching policy mid-authentication;
- a provisioned user can then continue with further required methods,
e.g. "AuthenticationMethods keyboard-interactive,publickey";
- users that are still unknown are reported as invalid when the
connection is closed, so a provisioned login does not leave a
failed-login record.
Public key, host-based and GSSAPI authentication keep requiring an
existing user.
The last patch is optional: it also lets the SSH "password" method
(non-interactive PAM) provision users, for stacks that
create the account in pam_authenticate().
[1] https://github.com/canonical/authd/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-auth-pam-Optionally-let-SSH-password-authentication-.patch
Type: text/x-patch
Size: 4127 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0009.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0008-auth-pam-Allow-keyboard-interactive-provisioning.patch
Type: text/x-patch
Size: 1870 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0010.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0007-monitor-Defer-unknown-users-when-PAMDeferUnknownUser.patch
Type: text/x-patch
Size: 3198 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0011.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-regress-Check-Match-scoping-for-PAMDeferUnknownUsers.patch
Type: text/x-patch
Size: 1493 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0012.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-auth2-Recheck-deferred-accounts-before-counting-a-PA.patch
Type: text/x-patch
Size: 5836 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0013.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-sshd-Report-deferred-invalid-users-on-connection-tea.patch
Type: text/x-patch
Size: 4121 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0014.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-monitor-Receive-PAM-account-requests-only-after-auth.patch
Type: text/x-patch
Size: 3249 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0015.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-auth-Distinguish-an-absent-user-from-a-failed-lookup.patch
Type: text/x-patch
Size: 2917 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0016.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-servconf-Add-PAMDeferUnknownUsers-configuration-opti.patch
Type: text/x-patch
Size: 4021 bytes
Desc: not available
URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20261118/4bd8eafe/attachment-0017.bin>
More information about the openssh-unix-dev
mailing list