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
ammarwith 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
π 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
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
β 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
Look for the line:
Account expires : Apr 15, 2024
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
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
β€οΈ 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)