配置客户端:
a、安装ldap客户端:
yum install nss-pam-ldapd pam_ldap -y
b、图形化配置:
LANG=C authconfig-tui
或者用命令修改:
authconfig --enablemkhomedir --disableldaptls --enableldap --enableldapauth --ldapserver=ldap://110.1.236.51 --ldapbasedn='dc=yinkp,dc=com' --update
cat /etc/sysconfig/authconfig |grep yes
1、增加/etc/openldap/ldap.conf
2、修改 /etc/nsswitch.conf中sss为ldap
3、 修改/etc/pam.d/system-auth,/etc/pam.d/password-auth
sed -i 's/pam_sss.so/pam_ldap.so/g' /etc/pam.d/system-auth
sed -i 's/pam_sss.so/pam_ldap.so/g' /etc/pam.d/password-auth
4、修改sssd配置文件:
vi /etc/sssd/sssd.conf
5、修改nslcd配置文件:
vi /etc/nslcd.conf
6、重启nslcd/sssd
service nslcd restart
service sssd restart
验证:
切换为系统中没有,ldap中有的用户。如果OK,则成功。
ldapsearch -x -b 'ou=people,dc=yinkp,dc=com'
批量修改主机使用ldap用户:
分发上面已经配置好的主机上的文件到其它linux主机
注:如果没有分发脚本,也可以一个一个文件scp
deploy.sh /etc/sysconfig/authconfig /etc/sysconfig/ all
deploy.sh /etc/openldap/ldap.conf /etc/openldap/ all
deploy.sh /etc/nsswitch.conf /etc/ all
deploy.sh /etc/pam.d/system-auth /etc/pam.d/ all
deploy.sh /etc/sssd/sssd.conf /etc/sssd/ all
deploy.sh /etc/nslcd.conf /etc/ all
重启nslcd/sssd服务
runRemoteCmd.sh "/bin/systemctl restart nslcd.service &&/bin/systemctl restart sssd.service" ldap_client
public DataSet GetUsersForGroup(string GroupName) { //if (GroupName.IndexOf('') > 0) //{ // return GetUsersForGroup(GroupName.Split(new char[] { '' })) //} if (GroupName == string.Empty) return null try { DirectoryEntry dir = GetDirectoryObject() dir.RefreshCache() DirectorySearcher ds = new DirectorySearcher(dir) ds.Filter = "(&(objectClass=group)(cn=" + GroupName + "))" ds.PropertiesToLoad.Add("memberof") SearchResult results = ds.FindOne() DataSet dsUser = new DataSet() DataTable tbUser = dsUser.Tables.Add("Users") tbUser.Columns.Add("GroupName") tbUser.Columns.Add("samaccountname") tbUser.Columns.Add("UserName") tbUser.Columns.Add("DisplayName") tbUser.Columns.Add("EMailAddress") tbUser.Columns.Add("primaryGroupID") if (results != null) { DirectoryEntry deGroup = new DirectoryEntry(results.Path, _ADUser, _ADPwd, AuthenticationTypes.Secure) System.DirectoryServices.PropertyCollection pcoll = deGroup.Properties int n = pcoll["member"].Count for (int i = 0 i < n i++) { DirectoryEntry deUser = new DirectoryEntry(_ADPath + "/" + pcoll["member"][i].ToString(), _ADUser, _ADPwd, AuthenticationTypes.Secure) try { DataRow rwUser = tbUser.NewRow() rwUser["GroupName"] = GroupName rwUser["samaccountname"] = GetProperty(deUser, "samaccountname") rwUser["UserName"] = GetProperty(deUser, "cn") rwUser["DisplayName"] = GetProperty(deUser, "givenName") + " " + GetProperty(deUser, "sn") rwUser["EMailAddress"] = GetProperty(deUser, "mail") rwUser["primaryGroupID"] = GetProperty(deUser, "primaryGroupID") tbUser.Rows.Add(rwUser) deUser.Close()欢迎分享,转载请注明来源:内存溢出
评论列表(0条)