Modifying entries using ldapmodify
You can use the ldapmodify tool to modify entries from the command line or by using an LDIF file that has the changetype:modify directive and value.
If you have more than one change, you can separate them using the - (dash) symbol.
Modifying an attribute from the command line
Steps
-
To locate a specific entry, run the
ldapsearchtool.Example:
$ bin/ldapsearch -h server.example.com -p 389 -D "cn=admin,dc=example,dc=com" \ -w password -b dc=example,dc=com "(uid=user.2004)" -
To change attributes from the command line, run the
ldapmodifycommand.-
Specify the modification using the
changetype:modifydirective and then specify which attributes are to be changed using thereplacedirective.Example:
In this example, we change the telephone number of a specific user entry.
$ bin/ldapmodify -h server.example.com -p 389 -D "cn=admin,dc=example,dc=com" \ -w password dn: uid=user.2004,ou=People,dc=example,dc=com changetype: modify replace: telephoneNumber telephoneNumber: +1 097 453 8232
-
-
Process the request:
Choose from:
-
For Unix EOF escape sequence, enter
ctrl+dtwice. -
For Windows, enter
ctrl+z.
-
Modifying multiple attributes in an entry from the command line
Steps
-
To locate a specific entry, run the
ldapsearchtool.Example:
$ bin/ldapsearch -h server.example.com -p 389 -D "cn=admin,dc=example,dc=com" \ -w password -b dc=example,dc=com "(uid=user.2004)" -
To change attributes from the command line, use the
ldapmodifycommand.-
Specify the modification using the
changetype:modifysubcommand. -
Specify the attributes to change using the
addandreplacesubcommand.Example:
In this example, we add the
postOfficeBoxattribute and change the mobile and telephone numbers of a specific user entry. ThepostOfficeBoxattribute must be present in your schema to allow the addition. The three changes are separated by a dash ("-").$ bin/ldapmodify -h server.example.com -p 389 -D "cn=admin,dc=example,dc=com" -w password dn: uid=user.2004,ou=People,dc=example,dc=com changetype: modify add: postOfficeBox postOfficeBox: 111 - replace: mobile mobile: +1 039 831 3737 - replace: telephoneNumber telephoneNumber: +1 097 453 8232
-
-
Process the request.
Choose from:
-
For Unix, enter
ctrl+dtwice.This is the Unix EOF escape sequence.
-
For Windows, enter
ctrl+z.
-
Adding an attribute from the command line
Steps
-
Run the
ldapmodifytool from the command line interface. -
Specify the modification using the
changetype:modifysubcommand. -
Specify which attributes to add using the
addoption.Example:
In this example, we add another value for the
cnattribute, which is multi-valued.$ bin/ldapmodify -h server.example.com -p 389 -D "cn=admin,dc=example,dc=com" \ -w password dn: uid=user.2004,ou=People,dc=example,dc=com changetype: modify add: cn cn: Sally Tea Tree -
To process the request, enter
ctrl+dtwice.This is the UNIX EOF escape sequence.
An error might occur if the attribute is single-valued, if the value already exists, if the value does not meet the proper syntax, or if the value does not meet the entry’s
objectclassrequirements.Remove any trailing spaces after the attribute value.
Adding an attribute using the language subtype
About this task
The PingDirectory server provides support for attributes using language subtypes. The operation must specifically match the subtype for successful operation. Any non-ASCII characters must be in UTF-8 format.
Steps
-
Run the
ldapmodifytool from the command line interface. -
Specify the modification using
changetype:modify. -
Specify which attributes to add using the
addoption.Example:
In this example, we add another value for the
langattribute.$ bin/ldapmodify -h server.example.com -p 389 -w password dn: uid=user.2004,ou=People,dc=example,dc=com changetype: modify add: postalAddress; lang-ko postalAddress; lang-ko:Byung-soon Kim$2020-14 Seoul -
To process the request, enter
ctrl+dtwice.This is the UNIX EOF escape sequence.
Adding an attribute using the binary subtype
About this task
The PingDirectory server provides support for attributes using binary subtypes, which are typically used for certificates or JPEG images that you can store in an entry. The operation must specifically match the subtype for successful operation. You must use the version directive with a value of "1" for binary subtypes. Typical binary attribute types are userCertificate and jpegPhoto.
Steps
-
To add an attribute with a binary subtype, run the
ldapmodifytool from the command line interface. -
Specify the modification using
changetype:modify. -
Specify which attributes to add using the
addoption.Example:
The attribute in this example points to the filepath of the certificate.
$ bin/ldapmodify -h server.example.com -p 389 -D "cn=admin,dc=example,dc=com" \ -w password version: 1 dn: uid=user.2004,ou=People,dc=example,dc=com changetype: modify add: userCertificate;binary userCertificate;binary:<file:///path/to/cert
Deleting an attribute
Steps
-
To delete an attribute, run the
ldapmodifytool with the LDIFdeletesubcommand.Example:
$ bin/ldapmodify -h server.example.com -p 389 -D "cn=admin,dc=example,dc=com" \ -w password dn: uid=user.2004,ou=People,dc=example,dc=com changetype: modify delete: employeeNumber
Deleting one value from an attribute with multiple values
About this task
Use the LDIF delete subcommand to delete a specific attribute value from an attribute.
Steps
-
Run the
ldapmodifytool from the command line. -
Specify the modification using
changetype:modify. -
Specify the attribute pair that you want to delete using
delete.Example:
The following sample assumes you have multiple values of
cnin an entry, such ascn: Sally Tree,cn: Sally Tea Tree. This sample keepscn:Sally Treeand deletes thecn: Sally Tea Tree.$ bin/ldapmodify -h server.example.com -p 389 -D "cn=admin,dc=example,dc=com" \ -w password dn: uid=user.2004,ou=People,dc=example,dc=com changetype: modify delete: cn cn: Sally Tea Tree
Renaming an entry
Rename an entry by changing the relative distinguished name (RDN) of an entry.
About this task
|
You cannot rename an RDN if it has children entries because this violates the LDAP protocol. |
Steps
-
Run the
ldapmodifytool to rename an entry.-
Run the
changetype,newrdn, anddeleteoldrdndirectives.Example:
The following command changes
uid=user.14touid=user.2014and uses thechangetype,newrdn, anddeleteoldrdndirectives.$ bin/ldapmodify dn: uid=user.14,ou=People,dc=example,dc=com changetype:moddn newrdn: uid=user.2014 deleteoldrdn: 1
-
Moving an entry within a PingDirectory server
Run the ldapmodify tool to move an entry from one base distinguished name (DN) to another base DN.
Before you begin
-
Assign access control instructions (ACIs) on the parent entries.
-
The source parent entry must have an ACI that allows export operations:
allow(export). -
The target parent entry must have an ACI that allows import operations:
allow(import).
-
About this task
For more information on access control instructions, see Overview of access control.
Steps
-
To move an entry from one branch to another, run the
ldapmodifytool.Example:
In this example, an entry moves from the
ou=contractorsbranch to theou=Peoplebranch.$ bin/ldapmodify dn: uid=user.14,ou=contractors,dc=example,dc=com changetype:moddn newrdn: uid=user.2014 deleteoldrdn: 0 newsuperior: ou=People,dc=example,dc=com -
Specify the modification using
changetype:moddn.
Moving an entry from one machine to another
About this task
The PingDirectory server provides the move-subtree tool to move a subtree or one entry on one machine to another.
The move-subtree tool moves a subtree or multiple entries from one machine to another. The tool does not copy the entries. After the entries are moved, they are no longer present on the source server.
|
The subtree or entry must exist on the source server and cannot be present on the target server. The source server must also support the |
Steps
-
To move an entry, such as
uid=test.user,ou=People,dc=example,dc=com, from the source host to the target host, run themove-subtreetool.Example:
$ bin/move-subtree --sourceHost source.example.com --sourcePort 389 \ --sourceBindDN "uid=admin,dc=example,dc=com" --sourceBindPassword password \ --targetHost target.example.com --targetPort 389 \ --targetBindDN "uid=admin,dc=example,dc=com" --targetBindPassword password \ --entryDN uid=test.user,ou=People,dc=example,dc=com
Moving multiple entries from one machine to another
About this task
The move-subtree tool provides the ability to move multiple entries listed in a distinguished name (DN) file from one machine to another. Lines that begin with the octothorpe character (#) and empty lines will be ignored. You can prefix entry DNs with dn: , but long DNs can’tt be wrapped across multiple lines.
Steps
-
In a text editor, create a new text file, enter a list of DNs, one DN per line, and then save the file.
You can also use the
ldapsearchcommand with the special character"1.1"to create a file containing a list of DNs that you want to move.Example:
The following example searches for all entries that match
"(department=Engineering)"and returns only the DNs that match the criteria. The results are re-directed to an output file,test-dns.ldif.$ bin/ldapsearch --baseDN dc=example,dc=com \ --searchScope sub "(department=Engineering)" "1.1" > test-dns.ldif -
To specify the file of DNs to move from one machine to another, run the
move-subtreetool with the--entryDNFileoption.Example:
$ bin/move-subtree --sourceHost source.example.com --sourcePort 389 \ --sourceBindDN "uid=admin,dc=example,dc=com" --sourceBindPassword password \ --targetHost target.example.com --targetPort 389 \ --targetBindDN "uid=admin,dc=example,dc=com" --targetBindPassword password \ --entryDNFile /path/to/file/test-dns.ldifIf an error occurs with one of the DNs in the file, the output message shows the error. The
move-subtreetool keeps processing the remaining DNs in the file.An error occurred while communicating with the target server: The entry uid=user.2,ou=People,dc=example,dc=com cannot be added because an entry with that name already exists Entry uid=user.3,ou=People,dc=example,dc=com was successfully moved from source.example.com:389 to target.example.com:389 Entry uid=user.4,ou=People,dc=example,dc=com was successfully moved from source.example.com:389 to target.example.com:389