How to force users to change their password upon first login?

In this tutorial we will force a new user to change the password upon first login. This is usually used by sysadmins. We will use a linux command 'chage' - which will change user password expiry information.

The chage command changes the number of days between password changes and the date of the last password change. This information is used by the system to determine when a user must change his/her password.

First lets start by creating a user "chia"

[root]# useradd chia

Setup a password for chia

[root]# passwd chia

Now, we will change the password expiry date to 0 so that the user "chia" will be forced to change the password on login.

[root]# chage -d 0 chia

If you read the man page of the command "chage", -d <days> means

Set the number of <days> since January 1st, 1970 when the password was last changed. The date may also be expressed in the format YYYY-MM-DD (or the format more commonly used in your area).

By using 0, we will automaticaly expire the passwd, forcing user to change it on first login.

Now when you login using chia

You are required to change your password immediately (root enforced)
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user chia.
Changing password for chia.
(current) UNIX password:

How to force every new user to change password at first login

For this change we need to change the default setting of useradd command.

[root]# vim /etc/default/useradd

Look for the line or just append the following line in the file.

Expire=0

How to force user to change password at first login in GUI

The same method works for GUI logins too. I have tried it on Ubuntu.


Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.