Linux用户暗码周期和到期条件示设置

何小豆儿在此  金牌会员 | 昨天 20:28 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 853|帖子 853|积分 2559

1、暗码周期策略介绍

  Linux暗码生存周期是指暗码从创建到失效的整个时间段,这个周期包罗了暗码的有效期、警告期、禁用期和最小/最大暗码更改间隔等参数,这些参数可以通过Linux系统的/etc/login.defs文件举行配置。在 Linux 系统中,实行有效的暗码更改与逾期策略是维护系统安全的关键,在暗码即将逾期之前,系统可以提前警告用户,以便用户有时间更改暗码,通过强制用户定期更改暗码,可以低落暗码被破解的风险,而暗码有效期策略则确保了纵然暗码被泄露,也不会长时间影响系统安全。
2、系统情况

  系统情况:RedHat 8.0
  重要配置文件:/etc/login.defs
3、文件内容及参数含义

  /etc/login.defs配置文件内容
  1. 1 [root@RedHat8 ~]# cat /etc/login.defs
  2. 2 #
  3. 3 # Please note that the parameters in this configuration file control the
  4. 4 # behavior of the tools from the shadow-utils component. None of these
  5. 5 # tools uses the PAM mechanism, and the utilities that use PAM (such as the
  6. 6 # passwd command) should therefore be configured elsewhere. Refer to
  7. 7 # /etc/pam.d/system-auth for more information.
  8. 8 #
  9. 9
  10. 10 # *REQUIRED*
  11. 11 #   Directory where mailboxes reside, _or_ name of file, relative to the
  12. 12 #   home directory.  If you _do_ define both, MAIL_DIR takes precedence.
  13. 13 #   QMAIL_DIR is for Qmail
  14. 14 #
  15. 15 #QMAIL_DIR      Maildir
  16. 16 MAIL_DIR        /var/spool/mail
  17. 17 #MAIL_FILE      .mail
  18. 18
  19. 19 # Password aging controls:
  20. 20 #
  21. 21 #       PASS_MAX_DAYS   Maximum number of days a password may be used.
  22. 22 #       PASS_MIN_DAYS   Minimum number of days allowed between password changes.
  23. 23 #       PASS_MIN_LEN    Minimum acceptable password length.
  24. 24 #       PASS_WARN_AGE   Number of days warning given before a password expires.
  25. 25 #
  26. 26 PASS_MAX_DAYS   99999
  27. 27 PASS_MIN_DAYS   0
  28. 28 PASS_MIN_LEN    5
  29. 29 PASS_WARN_AGE   7
  30. 30
  31. 31 #
  32. 32 # Min/max values for automatic uid selection in useradd
  33. 33 #
  34. 34 UID_MIN                  1000
  35. 35 UID_MAX                 60000
  36. 36 # System accounts
  37. 37 SYS_UID_MIN               201
  38. 38 SYS_UID_MAX               999
  39. 39
  40. 40 #
  41. 41 # Min/max values for automatic gid selection in groupadd
  42. 42 #
  43. 43 GID_MIN                  1000
  44. 44 GID_MAX                 60000
  45. 45 # System accounts
  46. 46 SYS_GID_MIN               201
  47. 47 SYS_GID_MAX               999
  48. 48
  49. 49 #
  50. 50 # If defined, this command is run when removing a user.
  51. 51 # It should remove any at/cron/print jobs etc. owned by
  52. 52 # the user to be removed (passed as the first argument).
  53. 53 #
  54. 54 #USERDEL_CMD    /usr/sbin/userdel_local
  55. 55
  56. 56 #
  57. 57 # If useradd should create home directories for users by default
  58. 58 # On RH systems, we do. This option is overridden with the -m flag on
  59. 59 # useradd command line.
  60. 60 #
  61. 61 CREATE_HOME     yes
  62. 62
  63. 63 # The permission mask is initialized to this value. If not specified,
  64. 64 # the permission mask will be initialized to 022.
  65. 65 UMASK           077
  66. 66
  67. 67 # This enables userdel to remove user groups if no members exist.
  68. 68 #
  69. 69 USERGROUPS_ENAB yes
  70. 70
  71. 71 # Use SHA512 to encrypt password.
  72. 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. 1 [root@RedHat8 ~]# cat /etc/login.defs
  2. 2 #
  3. 3 # Please note that the parameters in this configuration file control the
  4. 4 # behavior of the tools from the shadow-utils component. None of these
  5. 5 # tools uses the PAM mechanism, and the utilities that use PAM (such as the
  6. 6 # passwd command) should therefore be configured elsewhere. Refer to
  7. 7 # /etc/pam.d/system-auth for more information.
  8. 8 #
  9. 9
  10. 10 # *REQUIRED*
  11. 11 #   Directory where mailboxes reside, _or_ name of file, relative to the
  12. 12 #   home directory.  If you _do_ define both, MAIL_DIR takes precedence.
  13. 13 #   QMAIL_DIR is for Qmail
  14. 14 #
  15. 15 #QMAIL_DIR      Maildir
  16. 16 MAIL_DIR        /var/spool/mail
  17. 17 #MAIL_FILE      .mail
  18. 18
  19. 19 # Password aging controls:
  20. 20 #
  21. 21 #       PASS_MAX_DAYS   Maximum number of days a password may be used.
  22. 22 #       PASS_MIN_DAYS   Minimum number of days allowed between password changes.
  23. 23 #       PASS_MIN_LEN    Minimum acceptable password length.
  24. 24 #       PASS_WARN_AGE   Number of days warning given before a password expires.
  25. 25 #
  26. 26 PASS_MAX_DAYS   9
  27. 27 PASS_MIN_DAYS   1
  28. 28 PASS_MIN_LEN    12
  29. 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用户暗码的有效期、两次修改暗码的最短间隔时间和暗码到期条件示。
  使用命令:
  1. [root@RedHat8 ~]# chage -M 7 root    root密码最大有效期时间为7天
  2. [root@RedHat8 ~]# chage -m 3 root    root密码修改的最短间隔时间为3天
  3. [root@RedHat8 ~]# chage -W 8 root    root密码到期前8天提示
复制代码
  root账户暗码信息截图:

   root用户登录测试截图:

   root用户暗码修改测试:

   使用命令: chage -l root ,查看关于root账户的暗码相关信息。

   测试结论:使用chage命令后,用户的暗码有效期、暗码逾期前的提示已生效,但两次修改暗码的最短间隔时间未生效,暗码可以在短时间内正常修改(为什么没有生效不清楚,可以研究一下,有了解这一块的大佬,麻烦分享我一下)

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

何小豆儿在此

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表