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

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

Linux修改用户密码使用期限

用chage命令进行查看。

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@node2 ~ ]# chage --help
Usage: chage [options] LOGIN
 
Options:
  -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用户密码过期时间

1
2
3
4
5
6
7
8
[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 参数:强制用户下次登录时修改密码,看情况自行添加

1
2
3
4
5
6
7
8
9
10
[root@node2 ~ ]# chage -d 0 -m 0 -M 180 -W 15 root    设置密码最低有效期0-180天,提前15天发警报提醒
[root@node2 ~ ]# chage -l root
Last 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          密码更改之间的最短天数:0
Maximum number of days between password change      : 180        密码更改之间的最大天数:180天
Number of days of warning before password expires   : 15         密码过期前的警告天数:15天
[root@node2 ~ ]#

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@node2 ~ ]# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@node2 ~ ]#
[root@node2 ~ ]#
[root@node2 ~ ]# chage -l root
Last password change                    : Jun 24, 2019
Password expires                    : Jun 26, 2019
Password inactive                   : never
Account expires                     : never
Minimum number of days between password change      : 0
Maximum number of days between password change      : 2
Number of days of warning before password expires   : 1
[root@node2 ~ ]#

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

1
2
3
4
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

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

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

1
2
3
4
5
6
7
8
9
10
11
[root@node1 ~ 14:03:31]# chage -l aihuidi
Last password change                    : Jul 08, 2019
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
 
Last password change: 表示账号创建时的时间
Account expires: 表示账号到期时间

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

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

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

1
2
3
4
5
6
7
8
9
[root@node1 ~ 14:07:09]# chage -l aihuidi
Last password change                    : Jul 08, 2019
Password expires                    : never
Password inactive                   : never
Account expires                     : Jul 10, 2019
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@node1 ~ 14:07:13]#

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

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT俱乐部。

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/server/linux/15601.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部