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 an user to change their password when they login to the system next time.

List the users

First lets have a look at the users available in the system.

$ cut -d: -f1 /etc/passwd

Running the above code gives us the following result −

mail
news
uucp
proxy
www-data
backup
list
…
Ubuntu
uname1

Check user Details

Next we check the settings for users current password system configuration.

$ sudo chage -l uname1
[sudo] password for ubuntu:

Running the above code gives us the following result −

Last password change: Dec 30, 2019
Password expires: never
Password inactive: never
Account expires: never
Minimum number of days between password change: 0
Maximum number of days between password change: 99999
Number of days of warning before password expires: 7

Set the expire Option

Now we sue the expire option to set the timeline for password expiry and then query it with the chage to find the expiry implemented.

$ sudo passwd --expire uname1
passwd: password expiry information changed.
$ sudo chage -l uname1

Running the above code gives us the following result −

Last password change: password must be changed
Password expires: password must be changed
Password inactive: password must be changed
Account expires: never
Minimum number of days between password change: 0
Maximum number of days between password change: 99999
Number of days of warning before password expires: 7

Updated on: 03-Jan-2020

500 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements