Course contentsShow
← Linux
Lesson 844 of 1,8198. User Management and Pluggable Authentication ModulesFree lesson

Implementing Just-in-Time Provisioning

You will automatically create local accounts when a remote user authenticates for the first time.

In this lesson, you will learn how to automate the creation of local user accounts the very moment a remote user successfully authenticates for the first time.

The Concept of JIT Provisioning

In environments using centralized identity providers like LDAP or Active Directory, you often don't want to pre-populate your local /etc/passwd file with thousands of remote user entries. Instead, Just-in-Time (JIT) Provisioning allows the system to remain "lean" by creating a local user account only when a user actually attempts to log in.

This process is handled by the pam_mkhomedir.so module combined with identity lookup tools like SSSD. When a user authenticates, PAM verifies their credentials against the remote server. Once successful, the session management phase triggers a module that checks if the user has a local home directory. If they don’t, the system dynamically generates one, effectively "provisioning" the user environment on the fly.

Practical Implementation

To enable this, you typically update your common-session PAM configuration. Adding this line ensures that as soon as the authentication stack approves the user, the directory structure is built:

# Append to /etc/pam.d/common-session
session optional pam_mkhomedir.so skel=/etc/skel/ umask=0022

When a user logs in for the first time:

  1. Authentication: The system queries your remote directory (e.g., SSSD/LDAP).
  2. Authorization: The user is validated.
  3. Provisioning: pam_mkhomedir detects the missing home directory, copies the contents of /etc/skel/ to /home/remote_user, and sets the correct ownership.

This approach minimizes management overhead because you no longer need scripts to "sync" users before they start working. The system essentially treats the authentication success as a trigger to initialize the user's local workspace. It is a powerful way to bridge the gap between centralized identity management and local system usability.

Key Takeaway: Just-in-Time provisioning eliminates the need for manual user account creation by using PAM modules to dynamically generate home directories and user environments upon the first successful remote login.