Skip to content
Related Articles

Related Articles

Improve Article

How to Force User to Change Password at Next Login in Linux

  • Last Updated : 23 Aug, 2021

For security reasons, you must frequently change the password of accounts on the system. In this article, we are going to see how can we force the user to change the password on the next login in Linux. We can do that by two methods one is using passwd command and the other is by using chage command.

Using passwd command

To force a user to change the user account password, the current password must have expired. We can expire the password of the user using passwd command.passwd command provides -e or –expire option to expire the password of the user. Use the following command to expire the password of user

sudo passwd --expire username

After executing this command, the password will get expired. We can check the password expired or not using the chage command with -l option. Use the following command to verify password expired or not.

chag -l username

Next time when a user tries to log in to the system the user is prompted to change the current password.



Using chage Command

chage is a command-line tool that is used to update the user account ageing information. We can use the chage command to expire the password of an account.chage command provides -d or –lastday option, with this option mention the number of number day after January 1st, 1970 password should expire. So to expire password now we can use the 0 option. When we use 0 this means that the password is expired on January 1st, 1970, and it must be changed.

chage --lastday 0 username

We can verify the password is expired or not by using change command with the -l option.

On the next login, the system will ask the user to  reset the password.

My Personal Notes arrow_drop_up
Recommended Articles
Page :