Operations 5 min read

Force Users to Change Password on First Login with Linux chage

This guide shows how to create a Linux user, force an immediate password change on first login using the chage command, verify the behavior, and manage password expiration policies with practical examples and command explanations.

Open Source Linux
Open Source Linux
Open Source Linux
Force Users to Change Password on First Login with Linux chage

Preface

Linux forces users to change their password on the first login, a basic topic in user management for RHCE certification. This article records the steps to achieve that.

Experiment Process

1. Create user and set login password

[root@qll251 ~]# useradd user01
[root@qll251 ~]# echo "123123" | passwd --stdin user01
Changing password for user user01.
passwd: all authentication tokens updated successfully.

2. One‑line solution

[root@qll251 ~]# chage -d 0 user01
-d 0 user01 sets the password change date to 1970‑01‑01, causing the current password to expire immediately so the user must change it at the next login.

3. Verification

[root@qll251 ~]# ssh [email protected]
[email protected]'s password:
You are required to change your password immediately (root enforced)
Last login: Mon Jun  1 20:09:10 2020 from 10.43.187.251
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user user01.
(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Connection to 10.43.187.251 closed.

chage Command Explanation

The chage command manages password aging, allowing you to modify account and password validity periods.

chage command is used for password validity management, modifying the effective period of accounts and passwords.

Command parameters:

Usage examples:

1. View password expiration information for user01:

[root@qll251 ~]# chage -l user01
最近一次密码修改时间         :6月 01, 2020
密码过期时间                :从不
密码失效时间                :从不
帐户过期时间                :从不
两次改变密码之间相距的最小天数  :0
两次改变密码之间相距的最大天数  :99999
在密码过期之前警告的天数       :7

2. Set user01 password to expire after 90 days, require a minimum of 7 days between changes, and start warning 30 days before expiration:

[root@qll251 ~]# chage -M 90 -m 7 -W 30 user01
  设置完毕后,验证结果:
[root@qll251 ~]# chage -l user01
最近一次密码修改时间         :6月 01, 2020
密码过期时间                :8月 30, 2020
密码失效时间                :从不
帐户过期时间                :从不
两次改变密码之间相距的最小天数  :7
两次改变密码之间相距的最大天数  :90
在密码过期之前警告的天数       :30

Conclusion

If you found this article helpful, please consider liking, sharing, or following for more content.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSystem AdministrationUser Managementpassword-expirationchage
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.