在Linux系统管理中,有时候需要设置账号密码复杂度(长度)、密码过期策略等,这个主要是由/etc/login.defs参数文件中的一些参数控制的的。它主要用于用户账号限制,里面的参数主要有下面一些:

/etc/login.defs:

# Password aging controls:

#

#       PASS_MAX_DAYS   Maximum number of days a password may be used.

#       PASS_MIN_DAYS   Minimum number of days allowed between password changes.

#       PASS_MIN_LEN    Minimum acceptable password length.

#       PASS_WARN_AGE   Number of days warning given before a password expires.

 

 

PASS_MAX_DAYS 60      #密码最大有效期,此处参数PASS_MAX_DAYS为60,表示60天后,密码会过期。99999表示永不过期。

PASS_MIN_DAYS 0      #两次修改密码的最小间隔时间,0表示可以随时修改账号密码

PASS_MIN_LEN  8      #密码最小长度,对于root无效

PASS_WARN_AGE 7      #密码过期前多少天开始提示

 

#

# Min/max values for automatic uid selection in useradd

#

UID_MIN                   500

UID_MAX                 60000

 

UID_MIN    #用户ID的最小值

UID_MAX    #用户ID的最大值

 

#

# Min/max values for automatic gid selection in groupadd

#

GID_MIN                   500

GID_MAX                 60000

 

GID_MIN    #组ID最小值

GID_MAX    #组ID最大值

 

 

#

# If defined, this command is run when removing a user.

# It should remove any at/cron/print jobs etc. owned by

# the user to be removed (passed as the first argument).

#

#USERDEL_CMD    /usr/sbin/userdel_local

 

USERDEL_CMD    #默认注释状态,如果定义了该变量,表示当删除一个user时,应删除/打印/ cron的工作等所拥有的用户被删除(作为第一个参数传递)。

 

#

# If useradd should create home directories for users by default

# On RH systems, we do. This option is overridden with the -m flag on

# useradd command line.

#

CREATE_HOME     yes

 

CREATE_HOME  #表示是否创建用户home目录。

 

 

# The permission mask is initialized to this value. If not specified, 

# the permission mask will be initialized to 022.

UMASK           077

 

UMASK     #权限掩码初始化值

 

# This enables userdel to remove user groups if no members exist.

#

USERGROUPS_ENAB yes

 

USERGROUPS_ENAB   #该参数启用,表示userdel删除用户时,如果该用户用户组如果没有成员存在,则会删除该用户组

 

# Use MD5 or DES to encrypt password? Red Hat use MD5 by default.

MD5_CRYPT_ENAB yes

 

ENCRYPT_METHOD MD5   

 

ENCRYPT_METHOD  #表示用户密码加密方式,此处表示用MD5加密密码

修改了 /etc/login.defs下参数时,会立即生效,但是它只对修改后创建的用户生效。例如修改了PASS_MAX_DAYS参数等后,我们新建一个用户test。

[root@DB-Server home]# useradd test

[root@DB-Server home]# cat /etc/shadow | grep test

test:!!:16971:0:60:7:::

[root@DB-Server home]# cat /etc/passwd | grep test

test:x:501:501::/home/test:/bin/bash

[root@DB-Server home]# chage -l test

Last password change                                    : Jun 19, 2016

Password expires                                        : Aug 18, 2016

Password inactive                                       : never

Account expires                                         : never

Minimum number of days between password change          : 0

Maximum number of days between password change          : 60

Number of days of warning before password expires       : 7

[root@DB-Server home]# 

因为CREATE_HOME为yes,所以创建用户test后,就会默认在/home目录下创建test目录,这个可以在添加用户的规则文件/etc/default/useradd里面查看或修改

[root@DB-Server ~]# cat /etc/default/useradd

# useradd defaults file

GROUP=100

HOME=/home        #把用户的主目录建在/home中

INACTIVE=-1       #是否启用帐号过期停权,-1表示不启用

EXPIRE=           #帐号终止日期,不设置表示不启用;

SHELL=/bin/bash   #所用SHELL的类型;

SKEL=/etc/skel    #默认添加用户的目录默认文件存放位置;也就是说,当我们用adduser添加用户时,用户家目录下的文件,都是从这个目录中复制过去的

CREATE_MAIL_SPOOL=yes

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

[root@DB-Server ~]# chage -l test

Last password change                                    : Jun 19, 2016

Password expires                                        : Aug 18, 2016

Password inactive                                       : never

Account expires                                         : never

Minimum number of days between password change          : 0

Maximum number of days between password change          : 60

Number of days of warning before password expires       : 7

You have new mail in /var/spool/mail/root

[root@DB-Server ~]# chage -M 99999 test

[root@DB-Server ~]# chage -l test

Last password change                                    : Jun 19, 2016

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@DB-Server ~]# 

如上所示/etc/login.defs只是控制了账号的最小长度以及控制密码的有效期等,那么Linux是如何实现对用户的密码的复杂度的检查的呢?其实系统对密码的控制是有两部分组成:

1 cracklib

2 /etc/login.defs

pam_cracklib.so 才是控制密码复杂度的关键文件/lib/security/pam_cracklib.so, Redhat公司专门开发了cracklib这个安装包来判断密码的复杂度。如果你想查看pam_cracklib的一些参数,那么就使用下面命令

[root@DB-Server security]# man pam_cracklib

其中一些常见的参数为

 

retry=N

改变输入密码的次数,默认值是1。就是说,如果用户输入的密码强度不够就退出。可以使用这个选项设置输入的次数,以免一切都从头再来

 

              Prompt user at most N times before returning with error. The

              default is 1

 

minlen=N

新密码最低可接受的长度

 

              The minimum acceptable size for the new password (plus one if

              credits are not disabled which is the default). In addition to the

              number of characters in the new password, credit (of +1 in length)

              is given for each different kind of character (other, upper, lower

              and digit). The default for this parameter is 9 which is good for a

              old style UNIX password all of the same type of character but may

              be too low to exploit the added security of a md5 system. Note that

              there is a pair of length limits in Cracklib itself, a "way too

              short" limit of 4 which is hard coded in and a defined limit (6)

              that will be checked without reference to minlen. If you want to

              allow passwords as short as 5 characters you should not use this

              module.

 

difok=N

默认值为10。这个参数设置允许的新、旧密码相同字符的个数。不过,如果新密码中1/2的字符和旧密码不同,则新密码被接受

 

 

              This argument will change the default of 5 for the number of

              characters in the new password that must not be present in the old

              password. In addition, if 1/2 of the characters in the new password

              are different then the new password will be accepted anyway.

 

dcredit=N

限制新密码中至少有多少个数字

 

              (N >= 0) This is the maximum credit for having digits in the new

              password. If you have less than or N digits, each digit will count

              +1 towards meeting the current minlen value. The default for

              dcredit is 1 which is the recommended value for minlen less than

              10.

 

              (N < 0) This is the minimum number of digits that must be met for a

              new password.

 

ucredit=N

限制新密码中至少有多少个大写字符。

 

lcredit=N

限制新密码中至少有多少个小写字符。

例如在/etc/pam.d/system-auth 在password使用pam_cracklib.so设置的最后附加dcredit=3 ucredit=2

password    requisite     pam_cracklib.so try_first_pass retry=3 dcredit=3 ucredit=2

password    sufficient    pam_unix.so md5 shadow nullok try_first_pass use_authtok

password    required      pam_deny.so

此时如果你新建用户的密码不符合密码复杂度,就会出现BAD PASSWORD: it is based on a dictionary word提示。

[root@DB-Server ~]# passwd ttt

Changing password for user ttt.

New UNIX password: 

BAD PASSWORD: it is based on a dictionary word

 

参考资料:

http://www.cnblogs.com/xd502djj/archive/2011/11/23/2260094.html

http://blog.csdn.net/lhfeng/article/details/6033598

Linux账户密码过期安全策略设置的更多相关文章

  1. [ASP.NET] 如果将缓存“滑动过期时间”设置为1秒会怎样?

    今天编写了一个采用ASP.NET Caching的组件,在为它编写Unit Test的过程中发现了一个有趣的问题,接下来我通过一个简单的实例说明这个问题.我们在一个控制台应用中编写了如下一段程序,这个 ...

  2. linux上java路径设置

    linux上java路径设置 标签: javalinuxpath 2012-04-30 22:14 1843人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. 往/e ...

  3. I.MX6 Android Linux shell MMPF0100 i2c 设置数据

    #!/system/bin/busybox ash # # I.MX6 Android Linux shell MMPF0100 i2c 设置数据 # 说明: # 本文主要记录通过shell脚本来设置 ...

  4. Linux初始root密码设置

    刚安装好的Linux系统是没有设置root用户密码的,下边介绍如何设置root用户的密码 第一步:sudo passwd 第二步:输入密码 第三步:确认密码 这样三个步骤过后root用户的密码就设置好 ...

  5. Linux自动登陆的设置方法

    前些天为了实现Linux自动登陆的方法,在网上查了很多资料,发现有不少方法,但网上有些方法的讲解不是特别清楚,或者已经过时.因此,特意整理了一下Linux自动登陆的设置方法.本文的测试环境为Cento ...

  6. linux定时任务crontab的设置

    linux定时任务crontab的设置http://www.blogjava.net/freeman1984/archive/2010/09/23/332715.html vi /etc/cronta ...

  7. linux云服务器常用设置

    前面的话 由于在云服务器上配置自己的网站,将Linux里的常用设置记录如下 更改shell 默认地, ubuntu系统默认的shell是dash,但更常用的shell是bash 通过下面命令可以将da ...

  8. windows与虚拟机linux能ping通设置

    作为以后参考所用. 首先,介绍如何在VMWare中设置linux的网络.一般网络选项有Bridged,NAT,host-only几种,本次以host-only作详细说明,如下图: 在选择host-on ...

  9. 01_Linux系统系统语言查询,设置Xshell工具,中文显示,测试Xshell中文字符显示,Linux中文显示乱码设置

              Xshell是一个强大的安全终端模拟软件,它支持SSH1,SSH2,以及Microsoft Windows平台的TELNETNetSarang Xshell 4 Build 0 ...

随机推荐

  1. R语言介绍

    R语言简介 R语言是一种为统计计算和图形显示而设计的语言环境,是贝尔实验室(Bell Laboratories)的Rick Becker.John Chambers和Allan Wilks开发的S语言 ...

  2. 【Linux_Fedora_应用系列】_3_如何利用Smplayer播放WMV格式的文件

    在上一篇我们成功安装了视频播放器,并且成功安装里解码器[Linux_Fedora_应用系列]_2_如何安装视频播放器和视频文件解码 安装完的Smplayer的GUI的界面程序,可以播放FLV.AVI. ...

  3. 第 11 章 进度条媒体对象和 Well 组件

    学习要点: 1.Well 组件 2.进度条组件 3.媒体对象组件 主讲教师:李炎恢 本节课我们主要学习一下 Bootstrap 的三个组件功能:Well 组件.进度条组件.媒体对象组件. 一.Well ...

  4. ahjesus使用T4模板自动维护实体

    在entity项目里新建模板DBEntity.tt <#@ template debug="false" hostspecific="true" lang ...

  5. Mysql新增用户,权限管理

    MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant selec ...

  6. selenium启动firefox时加载扩展

    有些时候,我们测试需要用到插件或者已经导入的证书(比如金融和安全加密行业),而selenium启动firefox时会打开一个新的,不含有任何插件和个人证书的firefox(等同于全新安装后第一次打开的 ...

  7. 推荐12款实用的 JavaScript 书页翻转效果插件

    Flipbooks(书页)或者页面翻转已成为在网页设计中最流行的交互动画之一.他们可以用在 Flash,网页或者在线杂志中.使用书页动画或者页面翻转的网页设计效果方便人们展示他们的产品,作品或者其它内 ...

  8. jQuery的eq方法

    定义和用法eq() 方法将匹配元素集缩减值指定 index 上的一个. 语法.eq(index) 其中的index :整数,指示元素的位置(最小为 0).如果是负数,则从集合中的最后一个元素往回计数. ...

  9. 苹果浏览器和uc浏览器在移动端的坑(日常积累,随时更新)

    先mark 1 .  移动端uc浏览器不兼容css3 calc() 2 .  ie8下a标签没有内容给宽高也不能触发点击跳转 3 . safari输入框加上readOnly="ture&qu ...

  10. Hybrid框架UI重构之路:四、分而治之

    上文回顾:Hybird框架UI重构之路:三.工欲善其事,必先利其器 上一篇文章有说到less.grunt这两个工具,是为了css.js分模块使用的.UI框架提供给使用者的时候,是一个大的xxx.js. ...