天天看點

RH423-4 LDAP的功能模型二

 四、對目錄進行删除、添加entry

1、删除:ldapdelete      

#在删除的時候需要的是DN的資訊,是以最好先導出所要删除的條目

方法一:

[root@station2 ~]# ldapsearch -x "uid=zhangsan123"|grep dn

dn: uid=zhangsan123,ou=People,dc=station2,dc=example,dc=com

[root@station2 ~]# ldapdelete -x "uid=zhangsan123,ou=People,dc=station2,dc=example,dc=com" -W

Enter LDAP Password:

方法二:

[root@station2 ~]# ldapsearch -x "uid=zhangsan123"|grep dn >delzhangsan.ldif

[root@station2 ~]# vi delzhangsan.ldif

uid=zhangsan123,ou=People,dc=station2,dc=example,dc=com

[root@station2 ~]# ldapdelete -x -f delzhangsan.ldif -W

#這裡一定要加入-W 因為預設的使用者沒有删除他人的權限, 則一定要用管理者。也可以使用-r将整個子樹删掉。

2、添加:ldapadd

[root@station2 ~]# vi zhangsan.ldif

cn: zhangsam 123

sn: zhang

givenName: Emanuel

objectClass: top

objectClass: person

objectClass: organizationalPerson

objectClass: inetOrgPerson

ou: Product Testing

ou: People

l: Santa Clara

uid: zhangsan123

mail: [email protected]

telephoneNumber: +1 408 555 0933

facsimileTelephoneNumber: +1 408 555 9752

roomNumber: 3906

manager: uid=jwalker, ou=People, dc=station2,dc=example,dc=com

[root@station2 ~]# ldapadd -x -c -f zhangsan.ldif -W

adding new entry "uid=zhangsan123,ou=People,dc=station2,dc=example,dc=com"

2、修改一個已經存在的rdn的名字

[root@station2 ~]# ldapsearch -x "uid=zhangsan123" -LLL

[root@station2 ~]# vi modrdn.ldif

uid=zhangsan

[root@station2 ~]# ldapmodrdn -x -f modrdn.ldif -W

dn: uid=zhangsan,ou=People,dc=station2,dc=example,dc=com

uid: zhangsan

#多出uid: zhangsan 一行,則說明已經修改rdn了

4、利用ldapmodify修改LDAP的條目的屬性

l  添加add:changetype: modify

add: attributes

              Attributes: newvalue

如:

[root@station2 ~]# vi modif.ldif

changetype: modify

add: mail

[root@station2 ~]# ldapmodify -x -f modif.ldif -W

modifying entry "uid=zhangsan,ou=People,dc=station2,dc=example,dc=com"

l  删除delete:changetype: modify

             delete: attribute

             attribute: value

 如:

delete: mail

[root@station2 ~]# ldapmodify -x -f modif.ldif -W      

l  替換replace:changetype: modify

                  replace: attribute

                  attribute: newvalue

[root@station2 ~]# vi modif.ldif                

replace: mail

 [root@station2 ~]# ldapmodify -x -f modif.ldif -W

本文轉自netsword 51CTO部落格,原文連結:http://blog.51cto.com/netsword/541776

繼續閱讀