| Forum

How to force user to change password on first login in linux

I have to create multiple users for my project and force the users to change the password when they login to the system for the first time.

To create a user in linux,

adduser <yourusername>


adduser joe

Now set a temporary password for the user

passwd <yourusername>


passwd joe

To force the user to change the password on first login, you can force expire the password of the user by using the same passwd command. Although the passwd command is used to change the password of a user it supports a special flag to force expire the users password.

passwd --expire <yourusername>


passwrd --expire joe