How to set an expiry date for a user account in Linux?

Published August 1, 2021

To set an expiry date for a specific user, you can use the usermod command followed by the -e flag (expiry flag), then the expiry date in YYYY-MM-DD format, and then the name of the user to set the expiry date in Linux.

As an example, suppose we have a user called John, and we want to set the expiration date for this user account to 12th March 2022. Thus, when expressed in the YYYY-MM-DD format, it would be 2022-03-12.

Now let's use the usermod to set the expiration date. it can be done like this,

# Set an expiry date for a user account
# In our example, the expiry date
# is 12th March 2022 for the user 'john'
sudo usermod -e 2022-03-12 john
  • Sometimes you may need to use the sudo command before the usermod command to obtain the correct privileges to execute the command.

Now to verify whether the expiration date is set correctly, you can use the chage -l command followed by the name of the user in Linux. It can be like this,

# View user account expiry information
chage -l john

The output of the above command may look like this,

Yay 🎉! We have successfully set an expiration date for the user account john.

Try executing the above commands in this online terminal to see the results.

That's all 😃!

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter