Linux賬戶密碼到期安全性原則設定,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