Linux:賬戶鎖定策略的實現

來源:互聯網
上載者:User

為賬戶設定鎖定策略是安全基準配置裡面的一個要求,windows在組策略裡面可以很簡單設定,linux中可以使用pam的pam_tally2.so模組來實現。
  linux對賬戶的鎖定功能比windows的要更加廣泛,強大,windows組策略中的限制,只是在系統層面的限制,而linux藉助pam(Pluggable Authentication Modules,外掛程式式認證模組)的強大,不單止可以系統層面實現,還能在各中支援pam的應用中實現這種安全鎖定策略。
  瞭解pam_tally2模組:[root@localhost ~]# man pam_tally2.so PAM_TALLY2(8)                  Linux-PAM Manual                  PAM_TALLY2(8)
  NAME pam_tally2 - The login counter (tallying) module SYNOPSIS pam_tally2.so [file=/path/to/counter] [onerr=[fail|succeed]] [magic_root] [even_deny_root] [deny=n] [lock_time=n] [unlock_time=n] [root_unlock_time=n] [serialize] [audit] [silent] [no_log_info] pam_tally2 [——file /path/to/counter] [——user username] [——reset[=n]] [——quiet] DESCRIPTION This module maintains a count of attempted accesses, can reset count on success, can deny access if too many attempts fail. pam_tally2 comes in two parts: pam_tally2.so and pam_tally2. The former is the PAM module and the latter, a stand-alone program.  pam_tally2 is an (optional) application which can be used to interrogate and manipulate the counter file. It can display user‘s counts, set individual counts, or clear all counts. Setting artificially high counts may be useful for blocking users without changing their passwords. For example, one might find it useful to clear all counts every midnight from a cron job. Normally, failed attempts to access root will not cause the root account to become blocked, to prevent denial-of-service: if your users aren’t given shell accounts and root may only login via su or at the machine console (not telnet/rsh, etc), this is safe. pam_tally.so/pam_tally2.so模組會為使用者配置一個失敗登入計數器,每次的失敗登入會使計數器加1,到達閾值後將賬戶鎖定一段時間,由於pam_tally.so屬於比較老的版本,只能實現一旦失敗登入次數超過閾值後永久鎖定賬戶,直到root使用者將該使用者解鎖,pam_tally2.so則新增了unlock_time參數能實現自動解鎖。
  pam_tally2由兩部分組成:pam_tally2.so pam的模組和pam_tally2程式,pam_tally2用於查看和調整計數器,如手工解鎖使用者即是重設計數器。除非設定檔中加入even_root_deny參數,否則root使用者是不受到限制的。計數器會在使用者成功登入後被重設為零。
  pam_tally2.so主要參數:deny=n :失敗登入了n次就鎖定。
  lock_time=n :使用者每輸錯一次口令都要被鎖定的時間unlock_time=n:解鎖時間,使用者被鎖定後,最後一次失敗嘗試後過了n秒解鎖even_deny_root:使root同樣受限root_unlock_time=n:加了這個參數能特別的對root的解鎖時間設定,如果沒有這個參數就會使用unlock_time參數的值。
  file=/path/to/counter:指定計數器檔案的位置,預設是/var/log/tallylog
  執行個體操作:加大使用者口令被暴力破解的難度,是設定賬戶鎖定策略的目的。linux下的口令破解集中在sshd上,本文就以openssh服務作為執行個體來配置賬戶鎖定策略。
  策略要求如下:1.設定鎖定的閾值為5次2.鎖定時間為5分鐘即300秒3.必須所有使用者都受限,包括root修改openssh的pam設定檔,加入紅色的配置。
  vim /etc/pam.d/sshd #%PAM-1.0 auth       required        pam_tally2.so even_deny_root deny=5 unlock_time=300 auth       required        pam_sepermit.so auth       include          password-auth……        ……              ……
  使用root遠程ssh登入,輸入錯誤口令五次,在被登入的機器上輸入pam_tally2 [root@localhost ~]# pam_tally2 Login           Failures  Latest failure            From root                5       09/18/11 02:49:51   192.168.1.3 tom                5       09/18/11 02:50:00   192.168.1.3第六次登入,使用正確的口令,ssh仍然提示使用者名稱口令不正確,等待五分鐘後才能登入成功,再次在被登入的機器上輸入pam_tally2 [root@localhost ~]# pam_tally2 Login           Failures  Latest failure             From root                5        09/18/11 02:50:00   192.168.1.3看到root登入成功後,計數器被重設了。
  也可以使用命令:pam_tally2 –u tom——reset將使用者的計數器重設清零。
  總結:修改sshd的pam配置只能限制來自ssh的登入,如果把限制寫在longin的配置裡面,將能夠限制得更廣,telnet,rhost,本機登入都要受到限制。
  不足之處,不能為計數器設定一個重設的時間,只要使用者沒有成功登入過,計數器就一直在累計不會自動重設為零。最後,用鎖定帳號的方式來防暴力破解不是最佳的方式,真遇到暴力破解時容易造成使用者全部鎖死,影響系統的正常使用,最佳的方式是限制登入來源。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.