Set an expiry date for user accounts in Ubuntu

A System Administrator should utilize all available tools to effectively manage system resources. And, when some users may want to access system resources for a limited period of time. Then, it is better to grant them access for shorter duration. So, in this article, we cover how to set an expiry date for user accounts in Ubuntu.

One solution could have been to do it manually. That, when a user join the organization – create a user account. And, when the user leaves then disable it. The other way could have been if we could provide an expiry date the same day we create the user account.

Note: Following operations require superuser privileges. In case you don’t understand what you’re doing then, contact your System Administrator for further assistance.

Set an expiry date for user accounts in Ubuntu

There are two ways to set expiry date for user accounts.

Method I. Through usermod. usermod command-line utility helps us modify a user’s account. Use the following syntax to set an expiry date –

sudo usermod -e YYYY-MM-DD <user_name>

For instance, if we have a user abc and we want the expiry date for user to be – 01/01/2023 then,

sudo usermod -e 2023-01-01 abc

Use the above command again, if we want to modify the set expiry date. But, what if things change later and we want to get rid of expiry date in entirety. Then, use the following command –

sudo usermod -e '' <user_name>

For instance, in above example it should be –

sudo usermod -e '' abc

And, to view changes made – use chage command-line utility and look for Account Expires –

sudo chage -l <user_name>

Method II. We can also set an expiry date through chage utility itself –

sudo chage -E YYYY-MM-DD <user_name>

For instance, for user abc – Expiry date – May 24, 2023 –

sudo chage -E 2023-05-24 abc

To view the changes –

sudo chage -l abc

Lastly, to remove the expiry date –

sudo chage -E -1 <user_name>

In this case, it should be –

sudo chage -E -1 abc

In conclusion, we have covered how to set an expiry date for user accounts in Ubuntu through two command-line utilities – usermod and chage.

Similar Posts