100 Days of DevOps, Day 2: Temporary User Setup with Expiry



This content originally appeared on DEV Community and was authored by M. Oly Mahmud

Managing users is a basic task in DevOps. Not everyone needs permanent access. Sometimes, a developer or tester only needs access for a short time. In those cases, we can create temporary users. These users expire on a set date and remove the need for manual cleanup.

Why Temporary Users?

  • Security: old accounts close on time
  • Automation: no need to delete users later
  • Compliance: helps in audits
  • Clean system: fewer unused accounts

Step 1: Create a User with Expiry

We use useradd with the -e option.

sudo useradd -e 2026-01-28 mila
  • -e sets the expiry date
  • mila is the username

Step 2: Set a Password

We must add a password so the user can log in.

sudo passwd mila

It will ask us to type the password twice.

Step 3: Verify Expiry

We check the user details with:

sudo chage -l mila

Output will show:

Account expires : Jan 28, 2026

Quick One-Liner (Optional)

We can also do this in one command:

sudo useradd -e 2026-01-28 mila && echo "mila:DevOps@123" | sudo chpasswd

This creates the user, sets expiry, and adds a password in one go.

Conclusion

We learned how to create a temporary Linux user that expires automatically. This keeps our system secure and tidy with less manual work.

✨ Key Takeaways:

  • useradd -e → set expiry date
  • passwd or chpasswd → add a password
  • chage -l → check expiry date


This content originally appeared on DEV Community and was authored by M. Oly Mahmud