--- title: LDAP實戰 tags: Open distro description: View the slide with "Slide Mode". --- # LDAP實戰 <!-- Put the link to this slide here so people can follow --> ### [好懂](https://xiangyang17.pixnet.net/blog/post/25051251) ### 安裝套件 ```bash= yum -y install openldap-servers yum -y install openldap-clients yum -y install openldap yum -y install migrationtools yum -y install openldap-servers openldap-clients migrationtools ``` lsof -i -P -n | grep :80 ## `ldap` 指令 [簡易指令](http://benjr.tw/27676) ### ldapadd ```bash= [root@benjr ~]# ldapadd -x -D "cn=root,dc=benjr,dc=tw" -W -f BDN.ldif Enter LDAP Password: adding new entry "dc=benjr,dc=tw" x : 使用簡單的驗證(亦即,不用進行 SASL 認證) D : 指定 dn (Distinguished Name) 識別名稱連結 LDAP directory. W: 使用互動式輸入管理者密碼,有別於 -w(小寫)在twmand line 輸入密碼 f : 指定 LDIF 檔名 ``` >[name=昱齊] 看起來是一個DN對應到一個LDIF 檔案,DN一律為RootDN(cn=root或是cn=admin) >[LDIF範例](https://sparktsai.pixnet.net/blog/post/56578224-openldap-ldif-example),LDIF裡面可以存放帳號的相關資訊,像是密碼或者email等等 >[name=昱齊] DN如何對應到LDIF,是指像是我是管理人,我就看得到哪些哪些項目嗎 範例:新增使用者資訊 ```htmlmixed= #設定 吳怡君 通訊錄 dn: cn=li,ou=user,dc=xiang,dc=com cn: li sn: N/A objectclass: person objectclass: inetOrgPerson givenName: 吳怡君 mail: c293831287@l-penguin.idv.tw telephoneNumber: 02-29587572 mobile: 0939689593 postalAddress: 台北縣中和市景平路1號 postalCode: 235 ou: 人力資源部 title: 辦事員 ``` ldapmodify ldapsearch ### 設定密碼 ```bash= [root@localhost ~]# ldapadd -x -W -D "cn=Manager,dc=dic,dc=ksu" -f base.ldif Enter LDAP Password: <==這裡輸入你的 RootDN 密碼! adding new entry "dc=dic,dc=ksu" adding new entry "cn=Manager,dc=dic,dc=ksu" adding new entry "ou=People,dc=dic,dc=ksu" adding new entry "ou=Group,dc=dic,dc=ksu" ``` :::success 1. 安裝好 LDAP 伺服器軟體,並且提供登入 LDAP 功能的 <font color="#C98E85"> RootDN 密碼</font> 1. 載入 LDAP 所需要的環境設定參數檔 1. 啟動 LDAP 服務,並觀察 LDAP 服務的埠口,以啟用防火牆放行的功能 1. 預先指定好自己公司即將使用的 baseDN 環境 (最好與 DNS 系統相同即可),同時規劃好即將要使用的用戶端作業系統有哪些 1. 開始載入基本的 <font color="#C98E85">baseDN</font> 功能 1. 開始載入用戶端作業系統所需要的綱要檔 (schema) 1. 嘗試取得用戶端所需要的帳號參數範例檔,變轉為 LDAP 所需要的格式 <font color="#C98E85">(LDAP Data Interchange Format, LDIF)</font>,然後載入到 LDAP 伺服器內 1. 若需要加密環境,請前往 /etc/pki/tls/certs 目錄下進行所需要的 key 建制 :::