CentOS使用PAM鎖定多次登陸失敗的使用者的教程

來源:互聯網
上載者:User

Linux有一個pam_tally2.so的PAM模組,來限定使用者的登入失敗次數,如果次數達到設定的閾值,則鎖定使用者。

編譯PAM的設定檔

# vim /etc/pam.d/login

#%PAM-1.0  auth
required  pam_tally2.so
deny=3lock_time=300
even_deny_root root_unlock_time=10
auth [user_unknown=ignoresuccess=okignoreignore=ignore default=bad] pam_securetty.so
auth       include      system-auth
account    required     pam_nologin.so
account    include      system-auth  password
include      system-auth
# pam_selinux.so close should be the first session rule  session
required     pam_selinux.so close  session    optional     pam_keyinit.so force revoke
session    required     pam_loginuid.so  session    include      system-auth
session    optional     pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open

各參數解釋

even_deny_root    也限制root使用者;  deny           設定普通使用者和root使用者連續錯誤登陸的最大次數,超過最大次數,則鎖定該使用者  unlock_time        設定普通使用者鎖定後,多少時間後解鎖,單位是秒;  root_unlock_time      設定root使用者鎖定後,多少時間後解鎖,單位是秒;  此處使用的是 pam_tally2 模組,如果不支援 pam_tally2 可以使用 pam_tally 模組。另外,不同的pam版本,設定可能有所不同,具體使用方法,可以參照相關模組的使用規則。

在#%PAM-1.0的下面,即第二行,新增內容,一定要寫在前面,如果寫在後面,雖然使用者被鎖定,但是只要使用者輸入正確的密碼,還是可以登入的!

最終效果如下圖

這個只是限制了使用者從tty登入,而沒有限制遠程登入,如果想限制遠程登入,需要改SSHD檔案

# vim /etc/pam.d/sshd

#%PAM-1.0  auth          required        pam_tally2.so        deny=3unlock_time=300
even_deny_root root_unlock_time=10 auth       includesystem-auth
account    required     pam_nologin.so
account    includesystem-auth  password   include      system-auth
session    optional     pam_keyinit.so force revoke
session    include      system-auth  session    required     pam_loginuid.so

同樣是增加在第2行!

查看使用者登入失敗的次數

[root@node100 pam.d]
# pam_tally2 --user redhat  Login
Failures Latest failure  From
redhat7    07/16/12 15:18:22  tty1

解鎖指定使用者

[root@node100 pam.d]
# pam_tally2 -r -u redhat  Login
Failures Latest failure     From
redhat              7    07/16/12 15:18:22  tty1

這個遠程ssh的時候,沒有提示,我用的是Xshell,不知道其它終端有沒提示,只要超過設定的值,輸入正確的密碼也是登陸不了的!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.