In our last article, we’ve explained to you how to change user password expiry information in Linux, where we looked at different examples of the chage command. In this article, we will elaborate on how to forcefully make a user to change his/her password at the next login in Linux.

 

There are two possible ways to achieve this, as described in detail, below.

 

Using passwd Command

 

To force a user to change his/her password, first of all, the password must have expired and to cause a user’s password to expire, you can use the passwd command, which is used to change a user’s password by specifying the -e or --expire switch along with username as shown.

# passwd --expire vyga

 

Next, verify the user vyga’s password expiration and aging information with the chage command as shown.

# chage -l vyga

 

After running the passwd command above, you can see from the output of the chage command that the user’s password must be changed. Once the user vyga tries to login next time, he will be prompted to change his password before he can access a shell.

 

Using chage Command

 

Alternatively, you can use the chage command, with the -d or --lastday option which sets the number of days since January 1st, 1970 when the password was last changed.

 

Now to set the password expiry of user, run the following command by specifying the day to zero (0), means that the password has not been changed since the above date (i.e. January 1st, 1970), so the password has literally expired and needs to be changed immediately before the user can access the system again.

# chage --lastday 0 vyga
OR
# chage --lastday 1970-01-01 vyga

 

Next check the user vyga’s password expiration and aging information with the chage command using -l option as shown.

# chage -l vyga

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)