linux notes – restrict ldap netgroup users from login
這個範例是對學生群組限制他們登入某主機
首先 在 ldap 先建立 netgroup ou
# cat netgroup.ldif
dn: ou=netgroup, dc=xxx,dc=xxxxx,dc=edu,dc=tw
associatedDomain: xxx.xxxxx.edu.tw
ou: netgroup
objectClass: organizationalUnit
objectClass: top
objectClass: domainRelatedObject
在ldap 建立 netgroup students 群組 並加入學生帳號: user1 user2
# cat student.ldif
dn: cn=students, ou=netgroup, dc=xxx,dc=xxxxx,dc=edu,dc=tw
objectClass: nisNetgroup
objectClass: top
nisNetgroupTriple: (-,user1,-)
nisNetgroupTriple: (-,user2,-)
cn: students
加入 “account required pam_access.so” 這一行 到 /etc/pam.d/sshd 檔案
# vi /etc/pam.d/sshd
#%PAM-1.0
auth required pam_sepermit.so
auth include password-auth
account required pam_access.so # add this line
account required pam_nologin.so
account include password-auth
password include password-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open env_params
session optional pam_keyinit.so force revoke
session include password-auth
最後再加入 對學生的 students 登入限制 /etc/security/access.conf
# tail -n 1 /etc/security/access.conf
- : @students : ALL
這樣學生就不能登入某主機