Open In App

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

Last Updated : 21 Jul, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

For security reasons, you must frequently change the password of accounts on the system. In this article, we are going to see how we can 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 the `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 the user.

sudo passwd --expire username


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

sudo schag -l username


Using passwd command

Using passwd command

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 aging information. We can use the `chage` command to expire the password of an account. `chage` command provides `-d` or `–lastday` option, with this option mentioning the number of number days after January 1st, 1970 password should expire. So, to expire the password now we can use the 0 option. When we use 0 this means that the password 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 the change command with the `-l` option.

Using change command

Using change command

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

Additional Considerations

  • It is important to ensure that you have administrative privileges (root or sudo access) to execute the necessary commands.
  • Make sure to replace “username” with the actual username of the user whose password you want to expire.
  • The chage command provides additional options to manage user account aging, such as setting maximum and minimum password ages. Refer to the command’s documentation (man chage) for more details.

Conclusion

In this article we have discussed about how can we change our passwords at the next login Which is a crucial security practice in Linux system. Overall, we can say that by understanding this article one can easily enhance the security of their Linux environment and ensure that users regularly update their passwords to maintain a secure system.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads