1、暗码周期策略介绍
Linux暗码生存周期是指暗码从创建到失效的整个时间段,这个周期包罗了暗码的有效期、警告期、禁用期和最小/最大暗码更改间隔等参数,这些参数可以通过Linux系统的/etc/login.defs文件举行配置。在 Linux 系统中,实行有效的暗码更改与逾期策略是维护系统安全的关键,在暗码即将逾期之前,系统可以提前警告用户,以便用户有时间更改暗码,通过强制用户定期更改暗码,可以低落暗码被破解的风险,而暗码有效期策略则确保了纵然暗码被泄露,也不会长时间影响系统安全。
2、系统情况
系统情况:RedHat 8.0
重要配置文件:/etc/login.defs
3、文件内容及参数含义
/etc/login.defs配置文件内容- 1 [root@RedHat8 ~]# cat /etc/login.defs
- 2 #
- 3 # Please note that the parameters in this configuration file control the
- 4 # behavior of the tools from the shadow-utils component. None of these
- 5 # tools uses the PAM mechanism, and the utilities that use PAM (such as the
- 6 # passwd command) should therefore be configured elsewhere. Refer to
- 7 # /etc/pam.d/system-auth for more information.
- 8 #
- 9
- 10 # *REQUIRED*
- 11 # Directory where mailboxes reside, _or_ name of file, relative to the
- 12 # home directory. If you _do_ define both, MAIL_DIR takes precedence.
- 13 # QMAIL_DIR is for Qmail
- 14 #
- 15 #QMAIL_DIR Maildir
- 16 MAIL_DIR /var/spool/mail
- 17 #MAIL_FILE .mail
- 18
- 19 # Password aging controls:
- 20 #
- 21 # PASS_MAX_DAYS Maximum number of days a password may be used.
- 22 # PASS_MIN_DAYS Minimum number of days allowed between password changes.
- 23 # PASS_MIN_LEN Minimum acceptable password length.
- 24 # PASS_WARN_AGE Number of days warning given before a password expires.
- 25 #
- 26 PASS_MAX_DAYS 99999
- 27 PASS_MIN_DAYS 0
- 28 PASS_MIN_LEN 5
- 29 PASS_WARN_AGE 7
- 30
- 31 #
- 32 # Min/max values for automatic uid selection in useradd
- 33 #
- 34 UID_MIN 1000
- 35 UID_MAX 60000
- 36 # System accounts
- 37 SYS_UID_MIN 201
- 38 SYS_UID_MAX 999
- 39
- 40 #
- 41 # Min/max values for automatic gid selection in groupadd
- 42 #
- 43 GID_MIN 1000
- 44 GID_MAX 60000
- 45 # System accounts
- 46 SYS_GID_MIN 201
- 47 SYS_GID_MAX 999
- 48
- 49 #
- 50 # If defined, this command is run when removing a user.
- 51 # It should remove any at/cron/print jobs etc. owned by
- 52 # the user to be removed (passed as the first argument).
- 53 #
- 54 #USERDEL_CMD /usr/sbin/userdel_local
- 55
- 56 #
- 57 # If useradd should create home directories for users by default
- 58 # On RH systems, we do. This option is overridden with the -m flag on
- 59 # useradd command line.
- 60 #
- 61 CREATE_HOME yes
- 62
- 63 # The permission mask is initialized to this value. If not specified,
- 64 # the permission mask will be initialized to 022.
- 65 UMASK 077
- 66
- 67 # This enables userdel to remove user groups if no members exist.
- 68 #
- 69 USERGROUPS_ENAB yes
- 70
- 71 # Use SHA512 to encrypt password.
- 72 ENCRYPT_METHOD SHA512
复制代码 本次暗码周期策略实验中需要关注的配置文件参数含义如下:
PASS_MAX_DAYS 暗码使用的最大有效期天数
PASS_MIN_DAYS 两次修改暗码的最短间隔时间,为0时代表任何时间都可以更改暗码
PASS_MIN_LEN 暗码最小长度
PASS_WARN_AGE 暗码失效前的告警天数
4、修改/etc/login.defs配置文件
使用命令: vi /etc/login.defs 对配置文件举行编辑,修改配置文件参数如下:
PASS_MAX_DAYS 9
PASS_MIN_DAYS 1
PASS_MIN_LEN 12
PASS_WARN_AGE 10- 1 [root@RedHat8 ~]# cat /etc/login.defs
- 2 #
- 3 # Please note that the parameters in this configuration file control the
- 4 # behavior of the tools from the shadow-utils component. None of these
- 5 # tools uses the PAM mechanism, and the utilities that use PAM (such as the
- 6 # passwd command) should therefore be configured elsewhere. Refer to
- 7 # /etc/pam.d/system-auth for more information.
- 8 #
- 9
- 10 # *REQUIRED*
- 11 # Directory where mailboxes reside, _or_ name of file, relative to the
- 12 # home directory. If you _do_ define both, MAIL_DIR takes precedence.
- 13 # QMAIL_DIR is for Qmail
- 14 #
- 15 #QMAIL_DIR Maildir
- 16 MAIL_DIR /var/spool/mail
- 17 #MAIL_FILE .mail
- 18
- 19 # Password aging controls:
- 20 #
- 21 # PASS_MAX_DAYS Maximum number of days a password may be used.
- 22 # PASS_MIN_DAYS Minimum number of days allowed between password changes.
- 23 # PASS_MIN_LEN Minimum acceptable password length.
- 24 # PASS_WARN_AGE Number of days warning given before a password expires.
- 25 #
- 26 PASS_MAX_DAYS 9
- 27 PASS_MIN_DAYS 1
- 28 PASS_MIN_LEN 12
- 29 PASS_WARN_AGE 10
复制代码 5、测试
5.1、已有账户测试
暗码有效期测试截图:
用户登录测试:
暗码修改测试截图:
5.2、新用户测试
使用命令: useradd test ,新建test用户, passwd test ,设置test用户暗码123456
暗码有效期截图:
用户登录测试截图:
暗码修改测试截图:
5.3、测试结论
已有账户测试情况:从shadow文件中可以看出,暗码周期配置参数未生效,且在用户登录过程中也未收到暗码到期条件醒的消息,短时间内修改暗码操作乐成。
新建账户测试情况:从shadow文件中可以看出,暗码周期配置参数生效,并且在用户登录过程中收到暗码到期前的提示消息,但在短时间内依然可以正常修改暗码。
测试结论:对于在修改login.defs配置文件前就已经存在的用户,暗码周期策略不生效,对于在修改login.defs配置文件后新建的用户,暗码周期策略生效,且可以或许收到暗码到期前的提示消息,但两次修改暗码的最短间隔时间和暗码长度不生效,依然可以修改乐成。
5.4、延伸拓展
对于已有账户,若想实现暗码定期更换的本领,可通过chage命令来举行修改,chage命令用法如下:
使用chage命令修改root用户暗码的有效期、两次修改暗码的最短间隔时间和暗码到期条件示。
使用命令:- [root@RedHat8 ~]# chage -M 7 root root密码最大有效期时间为7天
- [root@RedHat8 ~]# chage -m 3 root root密码修改的最短间隔时间为3天
- [root@RedHat8 ~]# chage -W 8 root root密码到期前8天提示
复制代码 root账户暗码信息截图:
root用户登录测试截图:
root用户暗码修改测试:
使用命令: chage -l root ,查看关于root账户的暗码相关信息。
测试结论:使用chage命令后,用户的暗码有效期、暗码逾期前的提示已生效,但两次修改暗码的最短间隔时间未生效,暗码可以在短时间内正常修改(为什么没有生效不清楚,可以研究一下,有了解这一块的大佬,麻烦分享我一下)
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |