时间:2026-03-08 04:50:44

首页 / 攻略资讯 / 软件技术

Linux修改用户密码使用期限账号到期时间问题

Linux修改用户密码使用期限账号到期时间问题

Linux修改用户密码使用期限

用chage命令进行查看。

主要用与密码失效是通过此命令来管理

[root@node2 ~ ]# chage --helpUsage: chage [options] LOGINOptions: -d, --lastday LAST_DAY set date of last password change to LAST_DAY -E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE -h, --help display this help message and exit -I, --inactive INACTIVE set password inactive after expiration to INACTIVE -l, --list show account aging information -m, --mindays MIN_DAYS set minimum number of days before password change to MIN_DAYS -M, --maxdays MAX_DAYS set maximim number of days before password change to MAX_DAYS -R, --root CHROOT_DIR directory to chroot into -W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS[root@node2 ~ ]#

查看root用户密码过期时间

[root@node2 ~ ]# chage -l root Last password change: never Password expires: never Password inactive: never Account expires: never Minimum number of days between password change: 0 Maximum number of days between password change: 99999 密码永不过期 Number of days of warning before password expires: 7

设置root用户密码过期时间为180天提前15天发告警提醒修改密码

-d 参数:强制用户下次登录时修改密码,看情况自行添加

[root@node2 ~ ]# chage -d 0 -m 0 -M 180 -W 15 root 设置密码最低有效期0-180天,提前15天发警报提醒[root@node2 ~ ]# chage -l rootLast password change: Jun 20, 2019 最近一次密码更改:2019年6月20日Password expires: Dec 17, 2019 密码过期:2019年12月17日Password inactive: never 密码无效:从未Account expires: never 帐户过期:从未Minimum number of days between password change: 0 密码更改之间的最短天数:0Maximum number of days between password change: 180 密码更改之间的最大天数:180天Number of days of warning before password expires: 15 密码过期前的警告天数:15天[root@node2 ~ ]#

如果设置完查看是:密码必须修改,哪幺就要重置密码进行生效

重置密码让密码使用期限策略生效:

[root@node2 ~ ]# passwdChanging password for user root.New password: Retype new password: passwd: all authentication tokens updated successfully.[root@node2 ~ ]# [root@node2 ~ ]# [root@node2 ~ ]# chage -l rootLast password change: Jun 24, 2019Password expires: Jun 26, 2019Password inactive: neverAccount expires: neverMinimum number of days between password change: 0Maximum number of days between password change: 2Number of days of warning before password expires: 1[root@node2 ~ ]#

这个主要是由/etc/login.defs参数文件中的一些参数控制的的。它主要用于用户账号限制

PASS_MAX_DAYS 90 #密码最大有效期,表示90天后,密码会过期。99999表示永不过期。PASS_MIN_DAYS 0 #两次修改密码的最小间隔时间,0表示可以随时修改账号密码PASS_MIN_LEN 6 #密码最小长度,对于root无效PASS_WARN_AGE 10 #密码过期前多少天开始提示

修改了 /etc/login.defs下参数时,会立即生效,但是它只对修改后创建的用户生效

例如:我们新创建一个test用户

假如用户test有特殊需求,要求这个账号的密码永不过期,此时就可以使用chage命令来处理

设置账号过期时间

[root@node2 ~ ]# chage -E 2019-06-26 aihuidi aihuidi这个账号的有效期是2019-06-26

Linux系统中默认创建的用户的有效期限都是永久的

但有时候,我们需要对某些用户的有效期限做个限定

1、创建账号aihuidi

[root@node1 ~ 14:03:24]# useradd aihuidi

2、默认情况下,这个账号创建后,有效期是永久的,下面我们用命令来查看一下

[root@node1 ~ 14:03:31]# chage -l aihuidiLast password change: Jul 08, 2019Password expires: neverPassword inactive: neverAccount expires: neverMinimum number of days between password change: 0Maximum number of days between password change: 99999Number of days of warning before password expires: 7Last password change: 表示账号创建时的时间Account expires: 表示账号到期时间

3、按照需求,我们要对aihuidi这个用户,修改到期时间

[root@node1 ~ 14:03:36]# usermod -e "Jul 10,2019" aihuidi

然后我们确认一下是否修改成功:

[root@node1 ~ 14:07:09]# chage -l aihuidiLast password change: Jul 08, 2019Password expires: neverPassword inactive: neverAccount expires: Jul 10, 2019Minimum number of days between password change: 0Maximum number of days between password change: 99999Number of days of warning before password expires: 7[root@node1 ~ 14:07:13]#

发现aihuidi这个用户的有效时间截止到2019年的7月10号

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持8b8.cn。

Linux修改用户密码使用期限账号到期时间问题

系列软件