在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. 百度Java研发面经100题 总结

    1. 单例模式常见的应用场景分析. 在23种设计模式中,单例模式排行老大.虽然理解简单,但是对于应用场景.你真正的熟悉么?使用单例,是由于没必要每个请求都新建一个对象,这样既浪费CPU又浪费内存:之所 ...

  2. ThinkCMF-幻灯片制作

    在后台的扩展工具 -> 幻灯片分类 添加分类标识为"portal_index"的分类,然后在此分类添加幻灯片. 个人认为,此处可以用于: 1. 门户网站的首页幻灯片播放功能: ...

  3. 一次Debug过程的思考

    前一段时间,部门接入了新业务,由于业务量小,架构非常简单,采用了最简单的LNMP架构,整个项目是交给一个刚毕业的RD负责的,这是背景. 上线前半天,服务平稳运行.下午的时候,开始收到大量报警:No h ...

  4. ServletContext与网站计数器

    什么是ServletContext? ServletContext是服务器的一个公用的空间,是不同的浏览器共享的一个数据. 由图可以看出ServletContext和Cookie与session之间的 ...

  5. linux常用命令之文件系统

    df df - report file system disk space usage 查看文件系统的使用清空 用法 df [-hi] [path] 选项 -h human readable ,以人类 ...

  6. 初学File类

    对File类的基本方法的理解 今天刚开始学了File类 一开始看思想编程看得迷迷糊糊的,之后受不了了,直接去看API文档 归纳: File->java.util File类的主要方法: 构造方法 ...

  7. Struts2与Struts的区别

    Struts2与Struts的区别 从Struts2的发展过程来看,Struts2继承了Struts与WebWork的血脉,Struts2取两者之精华,形成新德框架,但是struts2还是更多的继承了 ...

  8. ionic + cordova 使用 cordova-plugin-crosswalk-webview 中的一些个坑

    1) 在使用Web Audio API 时,无法使用 AudioContext.decodeAudioData() 对MP3文件进行解码 2)使用Cordova-plugin-weibosdk 插件时 ...

  9. Git本地仓库

    原文:http://www.cnblogs.com/wilber2013/p/4189920.html Git基本概念 在Git中,我们将需要进行版本控制的文件目录叫做一个仓库(repository) ...

  10. 每天checklist所用到的T-CODE

    1.1重点检查 作业 事务码 检查过程 检查R/3系统是否已经启动 · 登录到R/3系统 检查每日备份是否正常 DB12-Backup Logs:Overview · 检查数据库备份 · 检查数据库备 ...