溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

linux如何實(shí)現(xiàn)賬號密碼安全加固

發(fā)布時間:2021-10-26 11:34:53 來源:億速云 閱讀:201 作者:小新 欄目:建站服務(wù)器

這篇文章將為大家詳細(xì)講解有關(guān)linux如何實(shí)現(xiàn)賬號密碼安全加固,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

Linux用戶密碼策略

    Linux用戶密碼的有效期,是否可以修改密碼可以通過login.defs文件控制.對login.defs文件修只影響后續(xù)建立的用戶,如果要改變以前建立的用戶的有效期等可以使用chage命令.

    Linux用戶密碼的復(fù)雜度可以通過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,該參數(shù)不再有效

PASS_WARN_AGE   7         #密碼失效前多少天在用戶登錄時通知用戶修改密碼

pam_cracklib主要參數(shù)說明:

    tretry=N:重試多少次后返回密碼修改錯誤

    difok=N:新密碼必需與舊密碼不同的位數(shù)

    dcredit=N: N >= 0:密碼中最多有多少個數(shù)字;N < 0密碼中最少有多少個數(shù)字.

    lcredit=N:小寶字母的個數(shù)

    ucredit=N大寶字母的個數(shù)

    credit=N:特殊字母的個數(shù)

    minclass=N:密碼組成(大/小字母,數(shù)字,特殊字符)

pam_passwdqc主要參數(shù)說明:

mix:設(shè)置口令字最小長度,默認(rèn)值是mix=disabled。

max:設(shè)置口令字的最大長度,默認(rèn)值是max=40。

passphrase:設(shè)置口令短語中單詞的最少個數(shù),默認(rèn)值是passphrase=3,如果為0則禁用口令短語。

atch:設(shè)置密碼串的常見程序,默認(rèn)值是match=4。

similar:設(shè)置當(dāng)我們重設(shè)口令時,重新設(shè)置的新口令能否與舊口令相似,它可以是similar=permit允許相似或similar=deny不允許相似。

random:設(shè)置隨機(jī)生成口令字的默認(rèn)長度。默認(rèn)值是random=42。設(shè)為0則禁止該功能。

enforce:設(shè)置約束范圍,enforce=none表示只警告弱口令字,但不禁止它們使用;enforce=users將對系統(tǒng)上的全體非根用戶實(shí)行這一限制;enforce=everyone將對包括根用戶在內(nèi)的全體用戶實(shí)行這一限制。

non-unix:它告訴這個模塊不要使用傳統(tǒng)的getpwnam函數(shù)調(diào)用獲得用戶信息,

retry:設(shè)置用戶輸入口令字時允許重試的次數(shù),默認(rèn)值是retry=3

密碼復(fù)雜度通過/etc/pam.d/system-auth實(shí)施

如:

要使用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系統(tǒng)的用戶帳號策略
編輯/etc/pam.d/system-auth 添加如下語句。
   auth required /lib/security/$ISA/pam_tally.so deny=5
   account required pam_tally.so
該語句的解釋:密碼最大聯(lián)系登錄6次,超過只能聯(lián)系管理員。


2、密碼策略
    2.1編輯/etc/login.defs  指定如下參數(shù)的值。
         PASS_MAX_DAYS   99999
         PASS_MIN_DAYS   0
         PASS_MIN_LEN    5
         PASS_WARN_AGE   7
         參數(shù)值得解釋: PASS_MAX_DAYS(設(shè)置密碼過期日期) 
              PASS_MIN_DAYS(設(shè)置密碼最少更改日期)
              PASS_MIN_LEN(設(shè)置密碼最小長度)時指密碼設(shè)置的最小長度,一般定義為8位以上
              PASS_WARN_AGE(設(shè)置過期提前警告天數(shù))
     2.2 設(shè)置賬戶鎖定登陸失敗鎖定次數(shù)、鎖定時間
         編輯/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
         解釋:設(shè)置位密碼連續(xù)六次鎖定,鎖定時間300秒 
         解鎖用戶 faillog -u <用戶名》 -r
     2.3 設(shè)置口令的復(fù)雜程度。
         編輯/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  在后面加一些參數(shù),
         例:password    requisite     pam_cracklib.so  minlen=8 ucredit=-2   lcredit=-2   dcredit=-5    ocredit=-1
         意思為最少有2個大寫字母,2個小寫字符,5個數(shù)字, 1個符號
     2.4 限制su的權(quán)限
         如果你不想任何人能夠用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,可以運(yùn)行如下命令
           # usermod -G10 admin
如何設(shè)置PAM模塊控制Linux密碼策略


  我們在使用linux系統(tǒng)設(shè)置密碼的時候,經(jīng)常遇到這樣的問題,系統(tǒng)提示:您的密碼太簡單,或者您的密碼是字典的一部分。那么系統(tǒng)是如何實(shí)現(xiàn)對用戶的密碼的復(fù)雜度的檢查的呢?
  系統(tǒng)對密碼的控制是有兩部分(我知道的)組成:
  1 cracklib
  2 login.defs
  聲明:login.defs主要是控制密碼的有效期。對密碼進(jìn)行時間管理。此處不細(xì)談
  login.defs --shadow password suite configuration
  pam_cracklib.so 才是控制密碼復(fù)雜度的關(guān)鍵文件
  redhat公司專門開發(fā)了cracklib這個安裝包來判斷密碼的復(fù)雜度
  可以rpm -ql cracklib查看
  密碼的復(fù)雜度的判斷是通過pam模塊控制來實(shí)現(xiàn)的,具體的模塊是pam_cracklibpam_cracklib 的參數(shù)介紹:
  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 //注:密碼字典,這個是驗(yàn)證用戶的密碼是否是字典一部分的關(guān)鍵。
  Path to the cracklib dictionaries.
  cracklib密碼強(qiáng)度檢測過程
  首先檢查密碼是否是字典的一部分,如果不是,則進(jìn)行下面的檢查
  密碼強(qiáng)度檢測過程
  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?
  新密碼的字符是否

關(guān)于“l(fā)inux如何實(shí)現(xiàn)賬號密碼安全加固”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI