Home | Mirror | Search

3. 基本操作

3.1. base-dn

建立基本DN

例 1.1. base-dn.ldif

dn: dc=bg7nyt,dc=cn
objectclass: dcObject
objectclass: organization
o:bg7nyt.net
dc: bg7nyt
description:Top level of directory

dn: cn=Manager,dc=bg7nyt,dc=cn
objectclass: organizationalRole
cn: Manager

dn: cn=admin,dc=bg7nyt,dc=cn
objectclass: organizationalRole
cn: admin

dn: cn=root,dc=bg7nyt,dc=cn
objectclass: organizationalRole
cn: root
		  		

ldapadd -x -D "cn=root,dc=bg7nyt,dc=cn" -W -f base-dn.ldif

3.2. Add

添加條目

		  		
[chenjingfeng@backup ldap]$ ldapadd -x -D "cn=root,dc=bg7nyt,dc=cn" -W -f base-dn.ldif
Enter LDAP Password:
adding new entry "dc=bg7nyt,dc=cn"

adding new entry "cn=Manager,dc=bg7nyt,dc=cn"

adding new entry "cn=admin,dc=bg7nyt,dc=cn"

adding new entry "cn=root,dc=bg7nyt,dc=cn"
				
				

查看條目

				
[chenjingfeng@backup ldap]$ ldapsearch -x -b 'dc=bg7nyt,dc=cn' '(objectclass=*)'
# extended LDIF
#
# LDAPv3
# base <dc=bg7nyt,dc=cn> with scope sub
# filter: (objectclass=*)
# requesting: ALL
#

# bg7nyt.cn
dn: dc=bg7nyt,dc=cn
objectClass: dcObject
objectClass: organization
o: bg7nyt.net
dc: bg7nyt
description: Top level of directory

# Manager, bg7nyt.cn
dn: cn=Manager,dc=bg7nyt,dc=cn
objectClass: organizationalRole
cn: Manager

# admin, bg7nyt.cn
dn: cn=admin,dc=bg7nyt,dc=cn
objectClass: organizationalRole
cn: admin

# root, bg7nyt.cn
dn: cn=root,dc=bg7nyt,dc=cn
objectClass: organizationalRole
cn: root

# search result
search: 2
result: 0 Success

# numResponses: 5
# numEntries: 4
				
			  

3.3. Search

3.4. Modify

3.5. Delete

刪除條目

ldapdelete -x -D "cn=root,dc=bg7nyt,dc=cn" -W "dc=bg7nyt,dc=cn"
			

3.6. Search

搜索條目

dn條目

ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts
				

結果

				
# extended LDIF
#
# LDAPv3
# base <> with scope base
# filter: (objectclass=*)
# requesting: namingContexts
#

#
dn:
namingContexts: dc=bg7nyt,dc=cn

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1
				
				

ldapsearch -x -b 'dc=bg7nyt,dc=cn'
				

3.7. Organization Unit

建立組織單元

例 1.2. ou.ldif

dn: ou=address,dc=bg7nyt,dc=cn
ou: address
objectClass: organizationalUnit

dn: cn=neo, ou=address, dc=bg7nyt,dc=cn
objectClass: person
cn: neo
sn: neo

dn: cn=netkiller, ou=address, dc=bg7nyt,dc=cn
objectClass: person
objectClass: inetOrgPerson
cn: netkiller
sn: netkiller
mail: openunix@163.com

dn: cn=bg7nyt, ou=address, dc=bg7nyt,dc=cn
objectClass: person
cn: bg7nyt
sn: bg7nyt
				

建立ou

[chenjingfeng@backup ldap]$ ldapadd -x -D "cn=root,dc=bg7nyt,dc=cn" -W -f ou.ldif
Enter LDAP Password:
adding new entry "ou=address,dc=bg7nyt,dc=cn"

adding new entry "cn=neo, ou=address, dc=bg7nyt,dc=cn"

adding new entry "cn=netkiller, ou=address, dc=bg7nyt,dc=cn"

adding new entry "cn=bg7nyt, ou=address, dc=bg7nyt,dc=cn"

			

刪除ou

[chenjingfeng@backup ldap]$ ldapdelete -x -D "cn=root,dc=bg7nyt,dc=cn" -W "ou=address,dc=bg7nyt,dc=cn"
Enter LDAP Password:
			
comments powered by Disqus