RHCA教程: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

Enter LDAP Password:

 

#這裏一定要加入-W 因爲默認的用戶沒有刪除他人的權限, 則一定要用管理員。也可以使用-r將整個子樹刪掉。

 

2、添加:ldapadd

[root@station2 ~]# vi zhangsan.ldif

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

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

Enter LDAP Password:

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

 

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

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

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

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 ~]# vi modrdn.ldif

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

uid=zhangsan

 

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

Enter LDAP Password:

 

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

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

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

uid: zhangsan

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

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

 

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

l  添加add:changetype: modify

add: attributes

              Attributes: newvalue

如:

[root@station2 ~]# vi modif.ldif

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

changetype: modify

add: mail

mail: [email protected]

 

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

Enter LDAP Password:

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

 

l  刪除delete:changetype: modify

             delete: attribute

             attribute: value

 如:

[root@station2 ~]# vi modif.ldif

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

changetype: modify

delete: mail

mail: [email protected]

 

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

Enter LDAP Password:

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

 

l  替換replace:changetype: modify

                  replace: attribute

                  attribute: newvalue

如:

[root@station2 ~]# vi modif.ldif               

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

changetype: modify

replace: mail

mail: [email protected]

 

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

Enter LDAP Password:

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

                        原文出自:        http://www.linuxidc.com/Linux/2011-04/34566.htm
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章