Linux账户密码过期安全策略设置
在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账户密码过期安全策略设置的更多相关文章
- [ASP.NET] 如果将缓存“滑动过期时间”设置为1秒会怎样?
今天编写了一个采用ASP.NET Caching的组件,在为它编写Unit Test的过程中发现了一个有趣的问题,接下来我通过一个简单的实例说明这个问题.我们在一个控制台应用中编写了如下一段程序,这个 ...
- linux上java路径设置
linux上java路径设置 标签: javalinuxpath 2012-04-30 22:14 1843人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. 往/e ...
- I.MX6 Android Linux shell MMPF0100 i2c 设置数据
#!/system/bin/busybox ash # # I.MX6 Android Linux shell MMPF0100 i2c 设置数据 # 说明: # 本文主要记录通过shell脚本来设置 ...
- Linux初始root密码设置
刚安装好的Linux系统是没有设置root用户密码的,下边介绍如何设置root用户的密码 第一步:sudo passwd 第二步:输入密码 第三步:确认密码 这样三个步骤过后root用户的密码就设置好 ...
- Linux自动登陆的设置方法
前些天为了实现Linux自动登陆的方法,在网上查了很多资料,发现有不少方法,但网上有些方法的讲解不是特别清楚,或者已经过时.因此,特意整理了一下Linux自动登陆的设置方法.本文的测试环境为Cento ...
- linux定时任务crontab的设置
linux定时任务crontab的设置http://www.blogjava.net/freeman1984/archive/2010/09/23/332715.html vi /etc/cronta ...
- linux云服务器常用设置
前面的话 由于在云服务器上配置自己的网站,将Linux里的常用设置记录如下 更改shell 默认地, ubuntu系统默认的shell是dash,但更常用的shell是bash 通过下面命令可以将da ...
- windows与虚拟机linux能ping通设置
作为以后参考所用. 首先,介绍如何在VMWare中设置linux的网络.一般网络选项有Bridged,NAT,host-only几种,本次以host-only作详细说明,如下图: 在选择host-on ...
- 01_Linux系统系统语言查询,设置Xshell工具,中文显示,测试Xshell中文字符显示,Linux中文显示乱码设置
Xshell是一个强大的安全终端模拟软件,它支持SSH1,SSH2,以及Microsoft Windows平台的TELNETNetSarang Xshell 4 Build 0 ...
随机推荐
- jQuery使用经验建议
在开发过很多 jQuery 插件以后,我慢慢的摸索出了一套开发jQuery插件比较标准的结构和模式.这样我就可以复制并粘贴大部分的代码结构,只要专注最主要的逻辑代码就行了. 使用相同的设计模式和架构也 ...
- IT技术开发人员获得成功的六大步骤
IT技术开发人士成功的6大步骤 一个前辈在移民加拿大后写的文章,写得不错,值得借鉴,转来给大家看看,也给自己 序言:经过001多年的洗礼,认识了这里这么多的JJMMGGDD,前几天刚得到签证, 无 ...
- 模式的混合-我們真的需要一次一次的讀配置嗎-MultitonPrototypeFactoryMethod
我們真的需要一次一次的讀配置嗎 通過配置文件,我們其實極大地優化了代碼的結構,很多易變的元素都可以通過配置來修訂. 配置文件是一個文件,那麼使用的時候不可避免的涉及到IO操作. 在內存不值錢的今天,我 ...
- 孙鑫MFC学习笔记6:菜单编程
1.对菜单响应的顺序: 视类,文档类,框架类,应用程序类 2.消息的分类 3.CWnd继承自CCmdTarget类, 所以从CWnd派生出的类也可以接收WM_COMMAND消息 4.命令的消息路由 5 ...
- PHP中利用GD实现的柱状图
PHP中利用GD实现的柱状图,自己写的一个画柱状图的类,上代码. <?php Class Chart{ private $image; // 定义图像 private $title; // 定义 ...
- Oracle 表分组 group by和模糊查询like
分组group by写法 select 字段名 from 表名 group by 字段名 查询这个字段名里的种类分组后可以加聚合函数select 字段名,聚合函数 from 表名 group by 字 ...
- CentOS 6.6 新安装系统的网络IP配置
实例环境 虚拟机:VMware 11.1.0 系统:CentOS 6.6 # ifconfig -a << 查看所有网卡的状态 2. # vi /etc/sysconfig/n ...
- GJM:用C#实现网络爬虫(二) [转载]
上一篇<用C#实现网络爬虫(一)>我们实现了网络通信的部分,接下来继续讨论爬虫的实现 3. 保存页面文件 这一部分可简单可复杂,如果只要简单地把HTML代码全部保存下来的话,直接存文件就行 ...
- MyBatis入门(一)
一.MyBaris简介 1)MyBaris发展过程 MyBatis的前身叫iBatis,本是apache的一个开源项目, 2010年这个项目由apache software foundation 迁移 ...
- 优秀工具推荐:两款很棒的 HTML5 游戏开发工具
HTML5 众多强大特性让我们不需要多么高深技术就能创建好玩的网页游戏,同时证明了开放的 Web 技术能与任何其他在游戏开发中使用的技术竞争.正如标题所说,这篇文章推荐的几款很棒 HTML5 游戏开发 ...


