生活随笔
收集整理的這篇文章主要介紹了
pam操作实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#1.怎樣才能強迫用戶設置的密碼不能與過去3次內的密碼重復?
修改/etc/pam.d/system-auth,增加pam_unix.so的參數,如下
[plain]?view plaincopy
password????sufficient????pam_unix.so?md5?shadow?nullok?try_first_pass?use_authtok?remember=3?? #2.如何要求用戶設置的密碼必須包含5個數字,3個特殊符號?
修改/etc/pam.d/system-auth,在password使用pam_cracklib.so設置的最后附加 dcredit=5,ocredit=3
[plain]?view plaincopy
password????requisite?????pam_cracklib.so?try_first_pass?retry=3?dcredit=5?ocredit=3?? ?#3.如何限制student最多同時登陸4個?
這需要pam_limits.so模塊。由于/etc/pam.d/system-auth中,默認就會通過pam_limits.so 限制用戶最多使用多少系統資源,因此
只需要在/etc/security/limits.conf 中加入以下內容(RHEL5最后就有,只不過注釋掉了)
[plain]?view plaincopy
student????????hard???????maxlogins???????4?? #4.某用戶連續登陸失敗3次以上就禁止登陸?
修改/etc/pam.d/system-auth
[plain]?view plaincopy
auth????????required??????pam_deny.so?? account????required??pam_tally.so?deny=3??#加入這一行?? account?????required??????pam_unix.so?? #5.如何限制root只能從veyun.com這臺計算機使用ssh遠程登陸?
#由于ssh服務器的程序文件使用sshd,而sshd剛好支持PAM,驗證如下:
[plain]?view plaincopy
[root@localhost?~]#?ldd?/usr/sbin/sshd?|?grep?libpam.so?? ????????libpam.so.0?=>?/lib/libpam.so.0?(0x00be2000)?? 修改/etc/pam.d/sshd,加入第二行,如下:
[python]?view plaincopy
auth???????include??????system-auth?? account??required????pam_access.so?accessfile=/etc/deny_sshd?? account????required?????pam_nologin.so?? #產生/etc/deny_sshd:
[plain]?view plaincopy
-:root:ALL?EXCEPT?veyun.com?? #6.自動建立主目錄:
PAM提供了一個pam_mkhomedir.so的模塊,當執行這個模塊時,它會檢查PAM客戶端用戶的主目錄是否存在,如果不存在則自動建立。
修改/etc/pam.d/login,在pam_selinux.so下面添加一行。
[plain]?view plaincopy
session????required?????pam_mkhomedir.so?skel=/etc/skel/?umask=0022?? 該方法特別適合使用網絡賬號的服務器,如使用NIS,LDAP等的域賬號
驗證如下:
[plain]?view plaincopy
[root@localhost?~]#?ls?/home?? aquota.user??lost+found??rhel??user??user1??user2??yhb?? [root@localhost?~]#?useradd?-M?lwy??#-M參數:不新建主目錄?? [root@localhost?~]#?ls?/home?? aquota.user??lost+found??rhel??user??user1??user2??yhb?? [root@localhost?~]#?passwd?lwy?? Changing?password?for?user?lwy.?? New?UNIX?password:??? BAD?PASSWORD:?it?is?WAY?too?short?? Retype?new?UNIX?password:??? passwd:?all?authentication?tokens?updated?successfully.?? [root@localhost?~]#??? 使用lwy用戶登錄:
總結
以上是生活随笔為你收集整理的pam操作实例的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。