LDAP從入門到實戰:環境部署與配置指南(下)

#作者:朱雷
接上篇:《LDAP從入門到實戰:環境部署與配置指南(上)》

鏈接: link

文章目錄

    • 2.5.添加賬號
    • 2.6.停止服務
    • 2.7.使用TLS證書
      • 2.7.1. TLS 證書
      • 2.7.2. TLS 配置
      • 2.7.3. 服務器配置
    • 2.8.使用安全連接的反向代理

2.5.添加賬號

添加管理員賬號配置文件

[root@localhost openldap]# cat  admin.ldif
dn: dc=zltest,dc=com
objectclass: dcObject
objectclass: organization
o: zl
dc: zltestdn: cn=admin,dc=zltest,dc=com
objectclass: organizationalRole
cn: admin

添加賬號

[root@localhost openldap]# ldapadd -x -D 'cn=admin,dc=zltest,dc=com' -W -f admin.ldif 
Enter LDAP Password:   # 輸入mdb數據庫配置的密碼
adding new entry "dc=zltest,dc=com"
adding new entry "cn=admin,dc=zltest,dc=com"

驗證添加

[root@localhost openldap]# ldapsearch -x -b 'dc=zltest,dc=com' '(objectclass=*)'
# extended LDIF
#
# LDAPv3
# base <dc=zltest,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
## zltest.com
dn: dc=zltest,dc=com
objectClass: dcObject
objectClass: organization
o: zl
dc: zltest# admin, zltest.com
dn: cn=admin,dc=zltest,dc=com
objectClass: organizationalRole
cn: admin# search result
search: 2
result: 0 Success# numResponses: 3
# numEntries: 2

創建具有組屬性的用戶文件

[root@localhost openldap]# cat  user.ldif 
dn: ou=oa,dc=zltest,dc=com
ou: oa
objectclass: organizationalUnitdn: cn=testuser,ou=oa,dc=zltest,dc=com
ou: oa
cn: testuser
sn: testuser
objectclass: inetOrgPerson
objectclass: organizationalPerson

添加用戶

[root@localhost openldap]# ldapadd -x -D 'cn=admin,dc=zltest,dc=com' -W -f user.ldif 
Enter LDAP Password: 
adding new entry "ou=oa,dc=zltest,dc=com"
adding new entry "cn=testuser,ou=oa,dc=zltest,dc=com"

驗證添加用戶

[root@localhost openldap]# ldapsearch -x -b 'dc=zltest,dc=com' '(objectclass=*)'
# extended LDIF
#
# LDAPv3
# base <dc=zltest,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
## zltest.com
dn: dc=zltest,dc=com
objectClass: dcObject
objectClass: organization
o: zl
dc: zltest
userPassword:: e1NIQX0rRG9XSGdBNFI0c2cyTjBCbGVOTTdqUmgyOGM9# admin, zltest.com
dn: cn=admin,dc=zltest,dc=com
objectClass: organizationalRole
cn: admin# oa, zltest.com
dn: ou=oa,dc=zltest,dc=com
ou: oa
objectClass: organizationalUnit# testuser, oa, zltest.com
dn: cn=testuser,ou=oa,dc=zltest,dc=com
ou: oa
cn: testuser
sn: testuser
objectClass: inetOrgPerson
objectClass: organizationalPerson# search result
search: 2
result: 0 Success# numResponses: 5
# numEntries: 4

修改用戶密碼

[root@localhost openldap]# ldappasswd -x -D 'cn=admin,dc=zltest,dc=com' -w 123456 -s 654321 'cn=testuser,ou=oa,dc=zltest,dc=com'
[root@localhost openldap]# ldapsearch -x -b 'cn=testuser,ou=oa,dc=zltest,dc=com' '(objectclass=*)'
# extended LDIF
#
# LDAPv3
# base <cn=testuser,ou=oa,dc=zltest,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
## testuser, oa, zltest.com
dn: cn=testuser,ou=oa,dc=zltest,dc=com
ou: oa
cn: testuser
sn: testuser
objectClass: inetOrgPerson
objectClass: organizationalPerson
userPassword:: e1NTSEF9eTZZVktFUmMraG0vcFZYTkVVbzBFcDJyZlQ0MWxUM1g=# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1

給用戶添加屬性

[root@localhost openldap]# cat  add_attr_testuser.ldif
dn: cn=testuser,ou=oa,dc=zltest,dc=com
changetype: modify
add: mail
mail: testuser@zltest.com
# 自己給自己添加屬性提示權限不足
[root@localhost openldap]# ldapmodify -x -W -D "cn=testuser,ou=oa,dc=zltest,dc=com" -f add_attr_testuser.ldif 
Enter LDAP Password: 
modifying entry "cn=testuser,ou=oa,dc=zltest,dc=com"
ldap_modify: Insufficient access (50)
# 需用管理員賬號添加
[root@localhost openldap]# ldapmodify -x -W -D "cn=admin,dc=zltest,dc=com" -f add_attr_testuser.ldif 
Enter LDAP Password: 
modifying entry "cn=testuser,ou=oa,dc=zltest,dc=com"

驗證添加用戶屬性結果

[root@localhost openldap]# ldapsearch -x -b 'cn=testuser,ou=oa,dc=zltest,dc=com' '(objectclass=*)'
# extended LDIF
#
# LDAPv3
# base <cn=testuser,ou=oa,dc=zltest,dc=com> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
## testuser, oa, zltest.com
dn: cn=testuser,ou=oa,dc=zltest,dc=com
ou: oa
cn: testuser
sn: testuser
objectClass: inetOrgPerson
objectClass: organizationalPerson
userPassword:: e1NTSEF9eTZZVktFUmMraG0vcFZYTkVVbzBFcDJyZlQ0MWxUM1g=
mail: testuser@zltest.com# search result
search: 2
result: 0 Success# numResponses: 2
# numEntries: 1

給用戶刪除屬性

[root@localhost openldap]# cat  delete_attr_testuser.ldif
dn: cn=testuser,ou=oa,dc=zltest,dc=com
changetype: modify
delete: mail

給用戶替換屬性

[root@localhost openldap]# cat  replace_attr_testuser.ldif
dn: cn=testuser,ou=oa,dc=zltest,dc=com
changetype: modify
replace: mail
mail: testuser_new@zltest.com

重命名用戶條目

[root@localhost openldap]# cat  replace_attr_testuser.ldif
dn: cn=testuser,ou=oa,dc=zltest,dc=com
changetype: modrdn
newrdn: oa=it
deleteoldrdn: 1

刪除用戶條目

[root@localhost openldap]# cat  delete_testuser.ldif 
dn: cn=testuser,ou=oa,dc=zltest,dc=com
changetype: delete
# 執行刪除命令
[root@localhost openldap]# ldapdelete -x -W -D "cn=admin,dc=zltest,dc=com" -f ./ delete_testuser.ldif
?
# 通過dn直接進行刪除
[root@localhost openldap]# ldapdelete -x -W -D "cn=admin,dc=zltest,dc=com" "cn=testuser,ou=oa,dc=zltest,dc=com"

2.6.停止服務

[root@localhost openldap]# kill -INT `cat /usr/local/var/run/slapd.pid`
[root@localhost openldap]# ps -ef|grep slapd
root        6603    5278  0 15:43 pts/1    00:00:00 grep --color=auto slapd

通過更激烈的方法殺死 slapd 可能會導致信息丟失或數據庫損壞

2.7.使用TLS證書

2.7.1. TLS 證書

OpenLDAP 客戶端和服務器能夠使用傳輸層安全性(TLS) 框架提供完整性和機密性保護。TLS 用途X.509證書用于承載客戶端和服務器身份。所有服務器都必須具有有效證書,而客戶端證書是可選的。

2.7.2. TLS 配置

獲取所需證書后,必須在客戶端和服務器上配置一些選項,以啟用 TLS 并使用證書。至少,必須為客戶端配置包含所有證書頒發機構(CA)證書。服務器必須配置加州證書以及它自己的服務器證書和私鑰。

通常,單個 CA 會頒發服務器證書和所有受信任的客戶端證書,因此服務器只需信任該簽名 CA。但是,客戶端可能希望連接到由不同組織管理的各種安全服務器,這些服務器的證書由許多不同的 CA 生成。因此,客戶端可能需要在其配置中包含許多不同的受信任 CA 的列表。

2.7.3. 服務器配置

# 簽署服務器證書的 CA 的證書
**TLSCACertificateFile** <CA文件名>
# 服務器證書
**TLSCertificateFile** <文件名>
# 服務器私鑰文件
**TLSCertificateKeyFile** <文件名>
# OpenSSL 的密碼規范,使用openssl ciphers -v ALL查看
TLSCipherSuite <密碼套件規范>
# 此指令指定在/dev/urandom不可用時從哪個文件獲取隨機數,如系統有則不需要此選項 
TLSRandFile <文件名>
# 包含 Diffie-Hellman 臨時密鑰交換參數的文件,使用基于 DHE 的密碼套件所必需的
TLSDHParamFile <文件名>
# 指定用于橢圓曲線 Diffie-Hellman 臨時密鑰交換的曲線。這是在 OpenSSL 中使用基于 ECDHE 的密碼套件所必需的:openssl ecparam -list_curves
TLSEC 名稱 <名稱>
# 指定在傳入 TLS 會話中對客戶端證書執行哪些檢查:
# 默認情況下,此選項設置為never ,在這種情況下,服務器永遠不會向客戶端索要證書。# 如果設置為allow,服務器將要求提供客戶端證書;如果沒有提供,會話將正常進行。如# 果提供了證書但服務器無法驗證,則忽略該證書并且會話正常進行,就像沒有提供證書一# 樣。如果設置為try,則請求證書,如果沒有提供證書,會話將正常進行。如果提供了證
# 書但無法驗證,則會話立即終止。如設置為demand,則請求證書并且必須提供有效證書,# 否則會話立即終止。
TLSVerifyClient { 從不 | 允許 | 嘗試 | 要求 }

標**的指令是必須的其他為可選

2.8.使用安全連接的反向代理

使用nginx、haproxy等反向代理軟件代理ldap 的389端口,在代理軟件上配置SSL/TSL認證,代理請求到后端ldap服務,特別在多主、多從的環境下特別實用。
Nginx配置stream proxy server:

https://nginx.org/en/docs/stream/ngx_stream_ssl_module.html
worker_processes auto;
stream {upstream ldap_backend {server 192.168.1.129:389;server 192.168.1.130:389;
}...server {listen               0.0.0.0:636 ssl;server_name         example.com;ssl_protocols       TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;ssl_certificate     /usr/local/nginx/conf/cert.pem;ssl_certificate_key /usr/local/nginx/conf/cert.key;ssl_session_cache   shared:SSL:10m;ssl_session_timeout 10m;proxy_pass  ldap_backend;...}

實際生產中推薦使用代理模式。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/74084.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/74084.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/74084.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

發現一個好用的Vue.js內置組件

目錄 一、這個好用的內置組件是什么&#xff1f; 二、這個組件的主要功能 三、怎么使用&#xff1f; 四、使用注意事項 五、我的使用場景 一、這個好用的內置組件是什么&#xff1f; 今天在優化我的平臺應用時&#xff0c;發現一個好用的組件標簽--<keep-alive>。 …

dart學習記錄5(類、對象)

1.獲取運行時對象類型 使用Object 屬性的 runtimeType&#xff0c;它返回一個 Type 對象。 print(a 的類型是 ${a.runtimeType});??警告 在測試對象的類型時建議使用object is Type比測試 object.runtimeType Type 更穩定。 2.實例變量的聲明 class Point {double? x;…

啟明星辰春招面試題

《網安面試指南》https://mp.weixin.qq.com/s/RIVYDmxI9g_TgGrpbdDKtA?token1860256701&langzh_CN 5000篇網安資料庫https://mp.weixin.qq.com/s?__bizMzkwNjY1Mzc0Nw&mid2247486065&idx2&snb30ade8200e842743339d428f414475e&chksmc0e4732df793fa3bf39…

Live555+Windows+MSys2 編譯Androidso庫和運行使用

下載 wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz tar -xzvf live555-latest.tar.gz加入版本控制 git init git add . git commit -a -m "first init" git log修改config.android-arm64 cd live vim config.android-arm64 ./genMakefile…

實用工具-Stirling-PDF

windows桌面版參考這個文檔 Getting Started | Stirling-PDF 安裝包推薦使用迅雷下載&#xff0c;先轉存到迅雷網盤在使用迅雷下載速度嘎嘎快。 github:https://github.com/Stirling-Tools/Stirling-PDF Stirling-PDF 是一個強大的、基于 Web 的開源 PDF 處理工具&#xff0c…

借助AI Agent實現數據分析

在當今數據驅動的世界中&#xff0c;數據分析已成為企業決策、科學研究和社會治理的核心工具。然而&#xff0c;隨著數據量的爆炸式增長和復雜性的提升&#xff0c;傳統的數據分析方法面臨著效率低下、成本高昂和人力不足等挑戰。AI技術的快速發展&#xff0c;尤其是AI Agent的…

JavaScript實現一個函數,將數組扁平化(flatten),即把多維數組轉為一維數組。

大白話實現一個函數&#xff0c;將數組扁平化&#xff08;flatten&#xff09;&#xff0c;即把多維數組轉為一維數組。 思路 實現數組扁平化的基本思路是遍歷數組中的每個元素&#xff0c;如果元素是數組&#xff0c;就遞歸地將其扁平化并添加到結果數組中&#xff1b;如果元…

麒麟操作系統安裝人大金倉數據庫

如果你想擁有你從未擁有過的東西&#xff0c;那么你必須去做你從未做過的事情 在當前數字化轉型和信息安全備受重視的背景下&#xff0c;眾多公司積極推進國產化改造進程。在操作系統領域&#xff0c;統信、open 歐拉、中標麒麟、銀河麒麟等國產操作系統嶄露頭角&#xff0c;逐…

開發SAPUI5 Fiori應用并部署到SAP系統

首先新建一個項目文件夾 在VScode中打開 打開SAP Fiori&#xff08;需要先下載安裝&#xff0c;參考上上一篇文章&#xff09; ,選擇已添加的SAP S4 ERP系統 ,點擊創建Firoi應用。 如果沒有添加系統的&#xff0c;點擊添加按鈕&#xff0c;添加即可&#xff0c;注意&#xff…

右鍵添加:新建HTML模板文件

使用注冊表給Windows右鍵添加:新建HTML文檔模板的功能_注冊表右鍵新建-CSDN博客 新建文件有了&#xff0c;但是沒有引用模板文件&#xff0c;是空文件。 默認改成 htmlfile 模板成功

[極客大挑戰 2019]Knife——3.20BUUCTF練習day4(1)

[極客大挑戰 2019]Knife——3.20BUUCTF練習day4(1) 很簡單 蟻劍連接 根目錄下有flag flag{f77e8444-dd87-48b3-8fe0-a735b5a5c708}

力扣22.括號生成

22. 括號生成 - 力扣&#xff08;LeetCode&#xff09; 代碼區&#xff1a; class Solution {vector<string> ans; public:vector<string> generateParenthesis(int n) {dfs(0,0,n,"");return ans;}void dfs(int left,int right,int n,string str){if(l…

第37周:文獻閱讀

目錄 摘要 Abstract 文獻閱讀 問題引入 研究背景 研究意義 研究目的 實驗方法 TimeGAN 數據增強 預測模型的獨立性 創新點 實驗研究 數據準備 合成數據分析 模型比較 總結 摘要 該文獻圍繞利用 TimeGAN 提高供熱變電站熱負荷預測精度展開。結構上&#x…

NFS 安裝與測試

NFS 安裝與測試 服務器 # NFS 共享目錄 mkdir -p ${HOME}/Share/nfs && sudo chown -R nobody:nogroup ${HOME}/Share/nfs# 安裝 NFS Server sudo apt install nfs-kernel-server# 配置 NFS 目錄 sudo cp -arf /etc/exports /etc/exports.bak sudo tee -a /etc/exports…

算法題(103):數獨

審題&#xff1a; 本題需要我們找出數獨的解&#xff0c;并打印出來 時間復雜度分析&#xff1a; 本題是9*9的數獨格子&#xff0c;所以數據量小于25&#xff0c;可以使用2^n的算法 思路&#xff1a; 方法一&#xff1a;深度優先搜索 首先確定搜索及插入策略&#xff1a; 我們采…

snmp/mib采用子代理模式,編碼,部署

0.環境 0.1 編譯net-snmp cd net-snmp-5.7.2 ./configure --prefix/usr/local/snmp BEGIN failed--compilation aborted at Makefile.PL line 1. make: *** [perlmakefiles] Error 2 yum install cpan -y make && make install /…

# [RPA] 使用八爪魚進行高效網頁數據采集

在許多行業中&#xff0c;數據是核心資產。然而&#xff0c;雖然許多網站的文本內容可以免費訪問&#xff0c;但手動一條一條采集&#xff0c;不僅耗時耗力&#xff0c;還容易出錯。這種情況下&#xff0c;使用自動化工具來提高采集效率就顯得尤為重要。本文將介紹 八爪魚 這一…

IDI_APPLICATION 與 IDC_ARROW資源存放在工程的哪個路徑?

書籍&#xff1a;《windows程序設計(第五版)》的開始 環境&#xff1a;visual studio 2022 內容&#xff1a;HELLOWIN程序 說明&#xff1a;以下內容大部分來自騰訊元寶。 IDI_APPLICATION 和 IDC_ARROW 是 ?Windows 系統預定義的資源標識符&#xff0c;它們并不以文件形式…

算法 | 優化算法比較

===================================================== github:https://github.com/MichaelBeechan CSDN:https://blog.csdn.net/u011344545 ===================================================== 優化算法 ?一、主流優化算法分類?1?、傳統梯度類算法?2?、啟發式算…

騰訊云HAI1元體驗:輕松調用DeepSeek-R1模型搭建網站

前言 隨著云計算和人工智能技術的不斷發展&#xff0c;構建和部署智能化的網頁變得越來越簡單。騰訊云提供的HAI&#xff08;人工智能平臺&#xff09;和DeepSeek&#xff08;智能搜索引擎&#xff09;服務&#xff0c;能幫助開發者快速搭建智能化網頁&#xff0c;提升用戶體驗…