Skip to content

Instantly share code, notes, and snippets.

@eeowaa
Created June 25, 2022 00:35
Show Gist options
  • Save eeowaa/8fc366f980972521ab650374d8ee01d3 to your computer and use it in GitHub Desktop.
Save eeowaa/8fc366f980972521ab650374d8ee01d3 to your computer and use it in GitHub Desktop.
Install an OpenLDAP server on Fedora 35
# Become root
sudo su -
# Install OpenLDAP and our favorite scriptable editor
dnf -y install openldap openldap-servers openldap-clients ed
# Define some parameters for our LDAP directory
BASEDN='dc=example,dc=com'
BINDDN="cn=Manager,$BASEDN"
PASSWD=`slappasswd -s password`
# Inject those parameters into the SLAPD config entries file
ed /usr/share/openldap-servers/slapd.ldif <<EOF
/olcSuffix:/s/.*/olcSuffix: $BASEDN/
/olcRootDN:/s/.*/olcRootDN: $BINDDN/
/olcRootDN:/a
olcRootPW: $PASSWD
.
wq
EOF
# Point local OpenLDAP clients to the local LDAP directory
ed /etc/openldap/ldap.conf <<EOF
/BASE/s.*/BASE $BASEDN/
/URI/s.*/URI ldap://localhost/
wq
EOF
# Fix ownership on OpenLDAP server directories
chown -R ldap:ldap /var/lib/ldap
chown -R ldap:ldap /etc/openldap/*
# Inject SLAPD config entries into the SLAPD database
rm -rf /etc/openldap/slapd.d/*
sudo -u ldap slapadd -F /etc/openldap/slapd.d/ \
-b cn=config -l /usr/share/openldap-servers/slapd.ldif
# Start the OpenLDAP server (a.k.a. SLAPD)
systemctl start slapd.service
# Create LDAP entries for the Base DN and Bind DN
ldapadd -x -D $BINDDN -w password <<EOF
dn: $BASEDN
objectClass: dcObject
objectClass: organization
dc: example
o: Example
description: Example directory
dn: $BINDDN
objectClass: organizationalRole
cn: Manager
description: Directory Manager
EOF
# Test LDAP search against the local LDAP directory
ldapsearch -D $BINDDN -w password -x '(objectclass=*)' -b $BASEDN