linux 賬號密碼安全加固

huangdazhu發表於2015-01-14

Red Hat Enterprise Linux AS release 4


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
     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?
  新密碼的字元是否是舊密碼字元的一個迴圈
  例如舊密碼:123
  新密碼:231
  Already used
  Was the password used in the past?
  這個密碼以前是否使用過
  Previously used passwords are to be found in /etc/security/opasswd.
  那麼系統是如何實現這個控制的呢?
  在系統的配置檔案/etc/pam.d/system-auth 中有這樣一行
  password requisite     pam_cracklib.so try_first_pass retry=3
  我們可以根據pam_cracklib的引數這樣配置這個pam模組來達到我們想要的目的
  password required /lib/security/pam_cracklib.so retry=3 type= minlen=8 difok=3 dictpath=/path/to/dict


賬號策略:
vi /etc/pam.d/system-auth
auth        required      pam_env.so
auth       required        pam_tally2.so even_deny_root deny=5 unlock_time=1800

注意:
1、順序不要錯,一定要在pam_env.so後面
2、deny:拒絕次數
3、even_deny_root:包含root使用者
4、
unlock_time:解鎖時間

手動解除鎖定:
檢視某一使用者錯誤登陸次數:
pam_tally –user

例如,檢視work使用者的錯誤登陸次數:
pam_tally –user work

清空某一使用者錯誤登陸次數:
pam_tally –user –reset

例如,清空 work 使用者的錯誤登陸次數,
pam_tally –user work –reset faillog -r 命令亦可。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28869493/viewspace-1401769/,如需轉載,請註明出處,否則將追究法律責任。

相關文章