How to Force User to Change Password at Next Login in Linux
Because of security concerns, the users in a system are required to update their passwords regularly. In this article, we will see how we can force a user to change their password when they login to the system next time.
List the users
First, let’s have a look at the users available in the system
# cut -d: -f1 /etc/passwd
There are two possible ways to achieve this, as described in detail, below
1. Using the “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 the username as shown.
# passwd --expire greencloud
Next, verify the user “greencloud” password expiration and aging information with the “chage” command as shown.
# chage -l greencloud
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 greencloud tries to log in next time, he will be prompted to change his password before he can access a shell as shown in the following screenshot.
2. 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 a user, run the following command by specifying the day to zero (0), which means that the password has not been changed since the above date (i.e. January 1st, 1970), so the password has expired and needs to be changed immediately before the user can access the system again.
# chage --lastday 0 greencloud Or # chage --lastday 1970-01-01 greencloud
Next, check the user’s password expiration and aging information with the chage command using the -l option as shown.
# chage -l greencloud
Conclusion
It is always recommended to remind users to change their account passwords regularly for security reasons. In this article, we have explained two ways to force users to change their password in the next login. You can ask any questions via the comment form below.
Good Luck!