How to create temporary user in Linux

In this article, we will see how to create temporary user in Linux. We can create user using useradd command by specifying expiry date. After expire date reached, the Linux user disabled.

-e, --expiredate EXPIRE_DATE 1. The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD. 2. If not specified, useradd will use the default expiry date specified by the EXPIRE variable in /etc/default/useradd, or an empty string (no expiry) by default.

1. Lets create temporary user in Linux

Create a user with expiry date of 29th December 2020.

useradd david -e 2020-12-29

2. Lets create temporary user in Linux for 30 days

Below user expired in 30 days from the date of created date.

useradd -e `date -d "30 days" +"%Y-%m-%d"` modi