使用者登入限制、鎖定與踢出,使用者登入限制鎖定
本文以SSH為例進行PAM配置來實現相應的認證功能,其它的登入方式配置相似,詳情可參考文章《PAM - 可插拔認證模組》。
1、限制使用者的登入(SSH)
(1)使用pam_access自訂限制規則
//新增pam_access模組認證[root@iZwz9catu2mrq92b07d1d0Z ~]# vi /etc/pam.d/sshd#%PAM-1.0account requisite pam_access.so nodefgroup accessfile=/etc/mypam/access_ssh.conf fieldsep=| listsep=,...//編輯accessfile(註:匹配的順序從第一行開始)[root@iZwz9catu2mrq92b07d1d0Z ~]# vi /etc/mypam/access_ssh.conf#允許root和組mygroup1的成員登入+|root (mygroup1)|ALL#拒絕root和組mygroup1的成員以外的使用者登入-|ALL EXCEPT root (mygroup1)|ALL#拒絕指定使用者從非指定的ip進行登入-|cjh|ALL EXCEPT 120.231.146.242
(2)使用pam_nologin限制非root使用者登入
[root@iZwz9catu2mrq92b07d1d0Z ~]# vi /etc/pam.d/sshd#%PAM-1.0...account required pam_nologin.so...[root@iZwz9catu2mrq92b07d1d0Z ~]# touch /etc/nologin//設定非root使用者登入失敗的提示資訊[root@iZwz9catu2mrq92b07d1d0Z ~]# vi /etc/nologin====================The system is upgrading================= Please wait a minute
2、鎖定多次登入失敗的使用者(SSH)
//新增pam_tally2模組認證,對3次嘗試訪問失敗的使用者進行鎖定,普通使用者鎖定30秒,root使用者鎖定60秒[root@iZwz9catu2mrq92b07d1d0Z ~]# vi /etc/pam.d/sshd#%PAM-1.0...auth required pam_tally2.so deny=3 unlock_time=30 even_deny_root root_unlock_time=60...//查看所有或指定使用者的錯誤訪問記錄[root@iZwz9catu2mrq92b07d1d0Z ~]# pam_tally2Login Failures Latest failure Fromcjh 1 11/19/17 19:25:25 120.230.146.242zhangsan 2 11/19/17 19:24:24 120.230.146.242[root@iZwz9catu2mrq92b07d1d0Z ~]# pam_tally2 --user cjhLogin Failures Latest failure Fromcjh 1 11/19/17 19:25:25 120.230.146.242//清空所有或指定使用者的錯誤訪問記錄[root@iZwz9catu2mrq92b07d1d0Z ~]# pam_tally2 --reset[root@iZwz9catu2mrq92b07d1d0Z ~]# pam_tally2 --reset --user cjh
3、踢出線上使用者
[root@iZwz9catu2mrq92b07d1d0Z ~]# whocjh tty2 2017-11-19 14:48root pts/0 2017-11-19 17:46 (120.230.146.242)zhangsan pts/3 2017-11-19 20:24 (120.230.146.242)[root@iZwz9catu2mrq92b07d1d0Z ~]# ps -ef| grep tty2cjh 8917 1806 0 14:48 tty2 00:00:00 -bash//踢出使用者cjh[root@iZwz9catu2mrq92b07d1d0Z ~]# kill -9 8917[root@iZwz9catu2mrq92b07d1d0Z ~]# whoroot pts/0 2017-11-19 17:46 (120.230.146.242)zhangsan pts/3 2017-11-19 20:24 (120.230.146.242)