DEV Community

Cover image for How to set an expiry date for a user account in Linux?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

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

Originally posted here!

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

The output of the above command may look like this,

chage linux command output

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 πŸ˜ƒ.


Discussion (0)