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

Managing Temporary Access for Contractors

You will provision time-limited access accounts with strict expiry dates.

Managing Temporary Access for Contractors

In this lesson, you will learn how to automate and enforce strict time-limited access for external contractors using built-in account expiration features.

When granting temporary access to Linux systems, the most common security failure is the "forgotten account"—a contractor leaves the project, but their credentials remain active, creating a significant security hole. Rather than relying on manual cleanup or recurring calendar reminders, you should bake the expiration date directly into the user account metadata at the moment of provisioning.

Enforcing Expiry with usermod

The Linux system provides the -e (expiredate) flag, which sets a hard "kill date" for an account. Once this date is reached, the account is automatically locked, preventing any further authentication via SSH or PAM, regardless of the password validity.

To provision a contractor account that expires on December 31st, 2024, use the following command:

# Create the user and set an expiry date (YYYY-MM-DD)
sudo useradd -e 2024-12-31 contractor_alice

# If the account already exists, update it:
sudo usermod -e 2024-12-31 contractor_alice

Verifying Account Status

You can audit the expiry settings for any user at any time by inspecting the account status with chage:

sudo chage -l contractor_alice

The output will clearly display the "Account expires" field. If you find that a project duration has been extended, you can update the date instantly using sudo chage -E 2025-03-01 contractor_alice.

This approach is superior to manual deletion because it acts as a "fail-closed" mechanism. Even if your team fails to run a cleanup script, the system’s own authentication stack (via PAM) will respect the metadata and deny access to the user once the threshold is crossed. For enterprise environments, you should integrate this expiry attribute directly into your automated onboarding workflows to ensure that every temporary account is born with a natural "expiration clock" ticking in the background.

Key Takeaway: Always pair contractor account creation with an explicit expiry date using the -e flag to ensure that access is automatically terminated without manual intervention.