DEV Community

Anusha Kuppili
Anusha Kuppili

Posted on

🕐 How to Create a Temporary Linux User with an Expiry Date (Real DevOps Task)

Ever needed to give someone temporary access to a Linux system—like a developer, intern, or contractor—but don’t want to manually remember to revoke it?

Let me show you how to do that using a real-world DevOps-style task.

Today’s goal is simple:

✅ Create a user named ammar with access only until 15th April 2024.

Let’s jump into the steps. 🛠️


✅ Step 1: Create the User with an Expiry Date

Run the following command in your terminal:

sudo useradd -e 2024-04-15 ammar
Enter fullscreen mode Exit fullscreen mode

🔍 What this does:

  • useradd – Command to create a new user
  • -e – Sets the expiry date for the account (format: YYYY-MM-DD)
  • ammar – The username being created

This ensures the system will automatically disable this account after April 15, 2024. 🎯


🔐 Step 2: Set a Password for the User

The user cannot log in until a password is assigned. Use this command:

sudo passwd ammar
Enter fullscreen mode Exit fullscreen mode

You’ll be prompted to enter and confirm the password.

Make sure to securely share it with the user.


📅 Step 3: Verify the Expiry Date

To confirm the user was created with the correct expiry date:

sudo chage -l ammar
Enter fullscreen mode Exit fullscreen mode

✅ Sample output:

Account expires    : Apr 15, 2024
Password expires   : never
Password inactive  : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Enter fullscreen mode Exit fullscreen mode

Look for the line:

Account expires    : Apr 15, 2024
Enter fullscreen mode Exit fullscreen mode

That confirms everything’s set up correctly!


🔁 (Optional) Step 4: Modify the Expiry Date Later

Need to extend or update the access duration?

sudo usermod -e 2024-05-15 ammar
Enter fullscreen mode Exit fullscreen mode

Just change the date to whatever is appropriate.


🧘 Why Should You Use Expiry Dates?

Setting expiry dates helps you:

  • 🔒 Avoid lingering, forgotten accounts
  • 🧹 Keep your system clean and secure
  • ✅ Follow enterprise security standards
  • ⏰ Automate temporary access control

This is especially important in shared or cloud-based environments.


🧪 Command Recap

Here’s a quick summary of everything we did:

# Step 1 - Create user with expiry
sudo useradd -e 2024-04-15 ammar

# Step 2 - Set password
sudo passwd ammar

# Step 3 - Verify expiry
sudo chage -l ammar

# (Optional) Step 4 - Modify expiry
sudo usermod -e 2024-05-15 ammar
Enter fullscreen mode Exit fullscreen mode

❤️ Final Thoughts

Creating temporary users in Linux is one of those small tasks that has huge security impact.

In just a few commands, you can:

  • ✅ Create a user
  • ✅ Set an automatic expiry
  • ✅ Keep your infrastructure secure and tidy

📺 Want to watch this in action? Head over to my YouTube channel Data Enthusiast Era for more DevOps tutorials, real-world tasks, and beginner-friendly breakdowns! 🎥

Until next time — stay curious, stay secure. 🔐✨

Top comments (0)