DEV Community

M. Oly Mahmud
M. Oly Mahmud

Posted on

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

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
Enter fullscreen mode Exit fullscreen mode
  • -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
Enter fullscreen mode Exit fullscreen mode

It will ask us to type the password twice.

Step 3: Verify Expiry

We check the user details with:

sudo chage -l mila
Enter fullscreen mode Exit fullscreen mode

Output will show:

Account expires : Jan 28, 2026
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)