From f0085644e073a12ca59d3921b6dfe0944a22779c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 18 Nov 2026 22:46:32 +0000 Subject: [PATCH 9/9] auth-pam: Optionally let SSH password authentication provision users With PasswordAuthentication, sshd passes the single secret to PAM non-interactively. Accept that method for deferred users too, for PAM stacks that create the account during pam_authenticate(). Refuse empty passwords for deferred users. --- auth-pam.c | 6 +++--- auth-passwd.c | 6 ++++-- monitor.c | 3 ++- sshd_config.5 | 7 ++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/auth-pam.c b/auth-pam.c index f3ebd987d..46bac9f7a 100644 --- a/auth-pam.c +++ b/auth-pam.c @@ -1271,8 +1271,8 @@ sshpam_auth_passwd(Authctxt *authctxt, const char *password) * by PermitRootLogin, use an invalid password to prevent leaking * information via timing (eg if the PAM config has a delay on fail). */ - if (!authctxt->valid || (authctxt->pw->pw_uid == 0 && - options.permit_root_login != PERMIT_YES)) + if ((!authctxt->valid && !authctxt->deferred) || + (authctxt->pw->pw_uid == 0 && options.permit_root_login != PERMIT_YES)) sshpam_password = fake = fake_password(password); sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, @@ -1290,7 +1290,7 @@ sshpam_auth_passwd(Authctxt *authctxt, const char *password) sshpam_err = check_pam_user(authctxt); if (sshpam_err == PAM_MAXTRIES) sshpam_set_maxtries_reached(1); - if (sshpam_err == PAM_SUCCESS && authctxt->valid) { + if (sshpam_err == PAM_SUCCESS && (authctxt->valid || authctxt->deferred)) { debug("PAM: password authentication accepted for %.100s", authctxt->user); return 1; diff --git a/auth-passwd.c b/auth-passwd.c index c5644f12e..c92ebfd08 100644 --- a/auth-passwd.c +++ b/auth-passwd.c @@ -93,7 +93,8 @@ auth_password(struct ssh *ssh, const char *password) if (pw->pw_uid == 0 && options.permit_root_login != PERMIT_YES) ok = 0; #endif - if (*password == '\0' && options.permit_empty_passwd == 0) + if (*password == '\0' && + (options.permit_empty_passwd == 0 || authctxt->deferred)) return 0; #ifdef KRB5 @@ -120,7 +121,8 @@ auth_password(struct ssh *ssh, const char *password) #endif #ifdef USE_PAM if (options.use_pam) - return (sshpam_auth_passwd(authctxt, password) && ok); + return (sshpam_auth_passwd(authctxt, password) && + (ok || authctxt->deferred)); #endif #if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE) if (!expire_checked) { diff --git a/monitor.c b/monitor.c index 18e547bd6..205d90926 100644 --- a/monitor.c +++ b/monitor.c @@ -323,7 +323,8 @@ monitor_child_preauth(struct ssh *ssh, struct monitor *pmonitor) #ifdef USE_PAM if (authenticated && authctxt->deferred) { - if (ent->type != MONITOR_REQ_PAM_FREE_CTX || + if ((ent->type != MONITOR_REQ_AUTHPASSWORD && + ent->type != MONITOR_REQ_PAM_FREE_CTX) || authctxt->service == NULL || strcmp(authctxt->service, "ssh-connection") != 0) fatal_f("unexpected authentication for deferred user"); diff --git a/sshd_config.5 b/sshd_config.5 index a47330684..27ea757d2 100644 --- a/sshd_config.5 +++ b/sshd_config.5 @@ -1458,9 +1458,14 @@ This allows a PAM module or name service module that creates accounts on their first login, such as one provided by a remote identity or directory service, to provision the account as part of authentication. .Pp -Only PAM keyboard-interactive authentication can provision an account. +PAM keyboard-interactive authentication can provision an account. The account must exist once that authentication, including PAM account management, has completed. +With +.Cm PasswordAuthentication , +PAM password authentication can also provision an account, as long as it is +created during PAM authentication, before PAM account management. +Empty passwords cannot be used to provision an account. .Pp If the effective server configuration changes after the user is created, the client must reconnect so authentication uses the new configuration -- 2.53.0