Batch 3: SQL Databases LDAP YAML ← Full TOC

← LDAP Index

📄 LDIF Format — LDIF syntax for add, modify, delete, rename entries

LDIF (LDAP Data Interchange Format) is the text format used to import/export LDAP data and to make changes. Used with ldapadd, ldapmodify, and ldapdelete command-line tools.

📋 Reference

ItemSyntax / ValueDescription
LDIF entrydn: uid=alice,ou=users,dc=mwu,dc=com\nobjectClass: inetOrgPerson\nuid: alice\n...Basic LDIF entry for adding a user
dn:dn: uid=alice,ou=users,dc=mwu,dc=comDistinguished Name — first line of every entry
objectClass:objectClass: inetOrgPersonObject class — can appear multiple times
attribute:mail: alice@example.comAttribute: value pair
Base64 valueuserPassword:: e1NTSEF9...==Double colon :: means base64-encoded value
URL valuejpegPhoto:< file:///path/photo.jpg< means value is loaded from URL/file
Comment# This is a commentLines starting with # are comments
Blank line(empty line)Separates entries in LDIF files
changetype: addchangetype: addAdd a new entry
changetype: modifychangetype: modifyModify an existing entry
add: attributeadd: telephoneNumber\ntelephoneNumber: +1-555-0200Add attribute value
replace: attributereplace: mail\nmail: newemail@example.comReplace attribute value
delete: attributedelete: telephoneNumberDelete all values of attribute
delete specificdelete: telephoneNumber\ntelephoneNumber: +1-555-0100Delete specific attribute value
-- (hyphen on its own line)Separate modification operations in changetype: modify
changetype: deletechangetype: deleteDelete an entry
changetype: modrdnchangetype: modrdn\nnewrdn: uid=alice2\ndeleteoldrdn: 1Rename entry
newsuperior:newsuperior: ou=alumni,dc=mwu,dc=comMove entry to different parent
version: 1version: 1LDIF version declaration (optional but recommended)
Continuation(space at start of continuation line)Long values wrap with space indent

💡 Example

# ── LDIF file: add_users.ldif ────────────────────────────────
version: 1

# Add organizational units first
dn: ou=users,dc=mywebuniversity,dc=com
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: users
description: All user accounts

dn: ou=groups,dc=mywebuniversity,dc=com
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: groups
description: All groups

# Add user Alice
dn: uid=alice,ou=users,dc=mywebuniversity,dc=com
changetype: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: alice
cn: Alice Smith
sn: Smith
givenName: Alice
displayName: Alice Smith
mail: alice@mywebuniversity.com
telephoneNumber: +1-555-0101
title: Senior Developer
departmentNumber: Engineering
employeeNumber: 1001
uidNumber: 10001
gidNumber: 5000
homeDirectory: /home/alice
loginShell: /bin/bash
userPassword: {SSHA}base64encodedhashedpassword==

# Add user Bob
dn: uid=bob,ou=users,dc=mywebuniversity,dc=com
changetype: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
uid: bob
cn: Bob Jones
sn: Jones
givenName: Bob
mail: bob@mywebuniversity.com
uidNumber: 10002
gidNumber: 5000
homeDirectory: /home/bob
loginShell: /bin/bash

# Add group
dn: cn=developers,ou=groups,dc=mywebuniversity,dc=com
changetype: add
objectClass: top
objectClass: groupOfNames
objectClass: posixGroup
cn: developers
gidNumber: 5001
member: uid=alice,ou=users,dc=mywebuniversity,dc=com
member: uid=bob,ou=users,dc=mywebuniversity,dc=com
description: Development team

# ── modify.ldif — modify existing entries ────────────────────

# Update Alice's phone and add manager
dn: uid=alice,ou=users,dc=mywebuniversity,dc=com
changetype: modify
replace: telephoneNumber
telephoneNumber: +1-555-0200
-
add: manager
manager: uid=dave,ou=users,dc=mywebuniversity,dc=com
-
add: description
description: Lead developer, Python team
-

# Add Carol to developers group
dn: cn=developers,ou=groups,dc=mywebuniversity,dc=com
changetype: modify
add: member
member: uid=carol,ou=users,dc=mywebuniversity,dc=com
-

# ── Apply with ldapadd / ldapmodify ──────────────────────────
# ldapadd    -x -H ldap://localhost -D "cn=admin,dc=mwu,dc=com" -W -f add_users.ldif
# ldapmodify -x -H ldap://localhost -D "cn=admin,dc=mwu,dc=com" -W -f modify.ldif
# ldapdelete -x -H ldap://localhost -D "cn=admin,dc=mwu,dc=com" -W "uid=bob,ou=users,dc=mwu,dc=com" 

← LDAP Concepts  |  🏠 Index  |  ldapsearch & CLI →