您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關linux如何實現賬號密碼安全加固,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
Linux用戶密碼策略
Linux用戶密碼的有效期,是否可以修改密碼可以通過login.defs文件控制.對login.defs文件修只影響后續建立的用戶,如果要改變以前建立的用戶的有效期等可以使用chage命令.
Linux用戶密碼的復雜度可以通過pam pam_cracklib module或pam_passwdqc module控制,兩者不能同時使用. 個人感覺pam_passwdqc更好用.
/etc/login.defs密碼策略
PASS_MAX_DAYS 99999 #密碼的最大有效期, 99999:永久有期
PASS_MIN_DAYS 0 #是否可修改密碼,0可修改,非0多少天后可修改
PASS_MIN_LEN 5 #密碼最小長度,使用pam_cracklib module,該參數不再有效
PASS_WARN_AGE 7 #密碼失效前多少天在用戶登錄時通知用戶修改密碼
pam_cracklib主要參數說明:
tretry=N:重試多少次后返回密碼修改錯誤
difok=N:新密碼必需與舊密碼不同的位數
dcredit=N: N >= 0:密碼中最多有多少個數字;N < 0密碼中最少有多少個數字.
lcredit=N:小寶字母的個數
ucredit=N大寶字母的個數
credit=N:特殊字母的個數
minclass=N:密碼組成(大/小字母,數字,特殊字符)
pam_passwdqc主要參數說明:
mix:設置口令字最小長度,默認值是mix=disabled。
max:設置口令字的最大長度,默認值是max=40。
passphrase:設置口令短語中單詞的最少個數,默認值是passphrase=3,如果為0則禁用口令短語。
atch:設置密碼串的常見程序,默認值是match=4。
similar:設置當我們重設口令時,重新設置的新口令能否與舊口令相似,它可以是similar=permit允許相似或similar=deny不允許相似。
random:設置隨機生成口令字的默認長度。默認值是random=42。設為0則禁止該功能。
enforce:設置約束范圍,enforce=none表示只警告弱口令字,但不禁止它們使用;enforce=users將對系統上的全體非根用戶實行這一限制;enforce=everyone將對包括根用戶在內的全體用戶實行這一限制。
non-unix:它告訴這個模塊不要使用傳統的getpwnam函數調用獲得用戶信息,
retry:設置用戶輸入口令字時允許重試的次數,默認值是retry=3
密碼復雜度通過/etc/pam.d/system-auth實施
如:
要使用pam_cracklib將注釋去掉,把pam_passwdqc.so注釋掉即可.
#password requisite /lib/security/$ISA/pam_cracklib.so retry=3 difok=1
password requisite /lib/security/$ISA/pam_passwdqc.so min=disabled,24,12,8,7 passphrase=3
password sufficient /lib/security/$ISA/pam_unix.so nullok use_authtok md5 shadow
#password requisite /lib/security/$ISA/pam_cracklib.so retry=3 difok=1
新密碼至少有一位與原來的不同.
加策略:
1、Linux系統的用戶帳號策略
編輯/etc/pam.d/system-auth 添加如下語句。
auth required /lib/security/$ISA/pam_tally.so deny=5
account required pam_tally.so
該語句的解釋:密碼最大聯系登錄6次,超過只能聯系管理員。
2、密碼策略
2.1編輯/etc/login.defs 指定如下參數的值。
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
參數值得解釋: PASS_MAX_DAYS(設置密碼過期日期)
PASS_MIN_DAYS(設置密碼最少更改日期)
PASS_MIN_LEN(設置密碼最小長度)時指密碼設置的最小長度,一般定義為8位以上
PASS_WARN_AGE(設置過期提前警告天數)
2.2 設置賬戶鎖定登陸失敗鎖定次數、鎖定時間
編輯/etc/pam.d/system- auth 首先 cp /etc/pam.d/system-auth /etc/pam.d/system-auth.bak
#vi /etc/pam.d/system-auth
auth required pam_tally.so onerr=fail deny=6 unlock_time=300
解釋:設置位密碼連續六次鎖定,鎖定時間300秒
解鎖用戶 faillog -u <用戶名》 -r
2.3 設置口令的復雜程度。
編輯/etc/pam.d/system- auth 首先 cp /etc/pam.d/system-auth /etc/pam.d/system-auth.bak
#vi /etc/pam.d/system-auth
找到pam_cracklib.so 在后面加一些參數,
例:password requisite pam_cracklib.so minlen=8 ucredit=-2 lcredit=-2 dcredit=-5 ocredit=-1
意思為最少有2個大寫字母,2個小寫字符,5個數字, 1個符號
2.4 限制su的權限
如果你不想任何人能夠用su作為root,可以編輯/etc/pam.d/su文件,增加如下兩行:
auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=isd
這時,僅isd組的用戶可以用su作為root。此后,如果你希望用戶admin能夠用su作為root,可以運行如下命令
# usermod -G10 admin
如何設置PAM模塊控制Linux密碼策略
我們在使用linux系統設置密碼的時候,經常遇到這樣的問題,系統提示:您的密碼太簡單,或者您的密碼是字典的一部分。那么系統是如何實現對用戶的密碼的復雜度的檢查的呢?
系統對密碼的控制是有兩部分(我知道的)組成:
1 cracklib
2 login.defs
聲明:login.defs主要是控制密碼的有效期。對密碼進行時間管理。此處不細談
login.defs --shadow password suite configuration
pam_cracklib.so 才是控制密碼復雜度的關鍵文件
redhat公司專門開發了cracklib這個安裝包來判斷密碼的復雜度
可以rpm -ql cracklib查看
密碼的復雜度的判斷是通過pam模塊控制來實現的,具體的模塊是pam_cracklibpam_cracklib 的參數介紹:
debug
This option makes the module write information to syslog(3) indicating the behavior of the module (this option does not write password information to the log file).
type=XXX
The default action is for the module to use the following prompts when requesting passwords: "New UNIX password: " and "Retype UNIX password: ". The default word UNIX can be replaced with this option.
retry=N
Prompt user at most N times before returning with error. The default is 1
difok=N
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.
difignore=N
How many characters should the password have before difok will be ignored. The default is 23.
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.
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
(N >= 0) This is the maximum credit for having upper case letters in the new password. If you have less than or N upper case letters each letter will count +1 towards meeting the current minlen value. The default for ucredit is 1 which is the recommended value for minlen less than 10.
(N > 0) This is the minimum number of upper case letters that must be met for a new password.
lcredit=N
(N >= 0) This is the maximum credit for having lower case letters in the new password. If you have less than or N lower case letters, each letter will count +1 towards meeting the current minlen value. The default for lcredit is 1 which is the recommended value for minlen less than 10.
(N < 0) This is the minimum number of lower case letters that must be met for a new password.
ocredit=N
(N >= 0) This is the maximum credit for having other characters in the new password. If you have less than or N other characters, each character will count +1 towards meeting the current minlen value. The default for ocredit is 1 which is the recommended value for minlen less than 10.
(N < 0) This is the minimum number of other characters that must be met for a new password.
use_authtok
This argument is used to force the module to not prompt the user for a new password but use the one provided by the previously stacked password module.
dictpath=/path/to/dict
Path to the cracklib dictionaries.
dictpath=/path/to/dict //注:密碼字典,這個是驗證用戶的密碼是否是字典一部分的關鍵。
Path to the cracklib dictionaries.
cracklib密碼強度檢測過程
首先檢查密碼是否是字典的一部分,如果不是,則進行下面的檢查
密碼強度檢測過程
These checks are:
Palindrome
Is the new password a palindrome of the old one?
新密碼是否舊密碼的回文
Case Change Only
Is the new password the the old one with only a change of case?
新密碼是否只是就密碼改變了大小寫
Similar
Is the new password too much like the old one?
新密碼是否和舊密碼很相似
This is primarily controlled by one argument, difok which is a number of characters that if different between the old and new are enough to accept the new password, this defaults to 10 or 1/2 the size of the new password whichever is smaller.
To avoid the lockup associated with trying to change a long and complicated password, difignore is available. This argument can be used to specify the minimum length a new password needs to be before the difok value is ignored. The default value for difignore is 23.
Simple
Is the new password too small?
新密碼是否太短
This is controlled by 5 arguments minlen, dcredit, ucredit, lcredit, and ocredit. See the section on the arguments for the details of how these work and there defaults.
Rotated
Is the new password a rotated version of the old password?
新密碼的字符是否
關于“linux如何實現賬號密碼安全加固”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。