问题

如何要求用户下次登录时更改密码?
只有在重置密码后,用户才必须在第一次强制更改密码。

检查确认

下次用户进行身份验证时(使用他们的旧密码),他们将被迫输入新密码。

# ssh testuser@localhost
testuser@localhost's password: 
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 testuser.
Changing password for testuser.
(current) UNIX password: 
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
Connection to localhost closed.

要验证当前密码是否已过期,请使用命令 chage。

# chage -l [username]

1. 使用 chage 命令

这可以使用带有 -d 选项的 chage 命令来完成。
根据 chage 的手册页:

# man chage
....
-d, --lastday LAST_DAY
    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). If the LAST_DAY is set to 0 the user is forced to change his password on the next log on.
...

要将用户上次更改密码的日期设置为 0,请使用以下命令:

# chage -d 0 [username]

例如,使用 chage 命令将上次密码更改的用户(testuser)日期设置为 0:

# chage -d 0 testuser
之路 on it Road.com

2.使用passwd命令

强制用户更改密码的另一种方法是使用带有 -e 选项的命令 passwd。
-e 选项使当前用户密码过期,强制用户在下次登录时设置新密码。
从 passwd 命令的手册页:

-e     This is a quick way to expire a password for an account. The user will be forced to change the password during the next login  attempt. Available  to  root only.

要使当前密码过期并强制用户设置新密码,请使用以下命令:

# passwd -e [username]

如果用户不记得他们的旧密码,请在运行上述命令之前使用 passwd 给他们一个临时密码。

UNIX/Linux:密码重置后如何强制用户在下次登录时更改密码
日期:2020-09-17 00:14:03 来源:oir作者:oir