Force Linux User to Change Password at Next Login
Think the passwords need to be changed by a certain user? Here's how to force a Linux user to change the password at the next login.
Due to security concerns, you may want to force the user to change the password on the next login.
So how do you do that?
Well, there are multiple ways to do so and I will walk you through multiple easy methods.
How to force the user to change the password on the next login
As I mentioned earlier, there are multiple ways to force the user to change the password on the next login and I will walk you through two ways of doing that:
- Using the passwd command
- Using the chage command
So let's start with the first one.
Using the passwd command
To force the user to chage his password on the next login using the passwd command, all you have to do is follow the given command syntax:
sudo passwd --expire [username]
For example, here, I want to for the user named
sagar to chage his password on the next login then I will be using the following:
sudo passwd --expire sagar
After executing the following command, when I tried to log back in as a user
sagar, it forced me to change my password before proceeding any further:
Using the chage command
So if you are a Linux admin, you must have heard of the chage command that allows you to manage users with various options and time ranges.
And if you want the user to change his password on the next login using this method, all you have to do is use the chage in the following manner:
sudo chage --lastday 0 [username]
Here, I forced the user
sagar to chage his password on the next login:
sudo chage --lastday 0 sagar
Now, even if you try to use the sudo or try to log back in, it will force you to chage the password:
And here you have it.
Use chage to the max potential
Forcing the user to change the password on the next login was one of the cool features of the chage command which means you can do a lot more than this.
Luckily, we already have a detailed guide on how you can use the chage command:
I hope you will find this guide helpful.
And if you have any queries, feel free to ask in the comments.