新聞中心
Linux LDAP用戶同步是為了在多個系統(tǒng)中實現(xiàn)用戶數(shù)據(jù)的同步,這是一種非常高效的方式。在實際應(yīng)用中,很多企業(yè)都會使用類似的技術(shù)來實現(xiàn)用戶數(shù)據(jù)的備份和恢復(fù)。下面將介紹一種基于Linux的LDAP用戶同步實現(xiàn)方法并講解其實現(xiàn)步驟。

目前創(chuàng)新互聯(lián)已為上千多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計、石柱土家族網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
1、LDAP的基本介紹
LDAP(Lightweight Directory Access Protocol,輕量目錄訪問協(xié)議),是基于X.500標準制定的一種網(wǎng)絡(luò)協(xié)議,主要用于訪問分布式的目錄服務(wù)。
在LDAP中,有三個常見的LDAP概念,分別是:entry,attribute和DN。
entry(條目):所謂條目是指就像我們平時使用的名片一樣,其中包含了很多信息,這些信息都是我們在條目中填寫的。
attribute(屬性):每個條目都有多個屬性,例如姓名,,地址等等。每個屬性又有一個或多個值,比如號碼就有可能有多個,一個家里可能有多個號碼,所以它就是多值屬性。
DN(Distinguished Name, 區(qū)別名稱):DN記錄了一個條目的完整路徑,比如一般的DN路徑格式是:countryName=CN, organizationName=Company, commonName=username, 讀作cn=username, o=Company, c=CN。
2、LDAP的用戶同步
在實際應(yīng)用中,經(jīng)常需要對多臺機器上的用戶進行同步,這里提供一種基于LDAP的用戶同步實現(xiàn)方案:
Step1:搭建LDAP服務(wù)器
我們需要搭建一個OpenLDAP服務(wù)器,在CentOS下一鍵安裝命令如下:
yum install -y openldap openldap-servers openldap-clients
在安裝完成后,我們需要對LDAP進行一些配置:
1. 制作LDAP管理員用戶
slappasswd -s ‘password’ 生成加密后的密碼
vim manager_pw.ldif #編寫管理員密碼文件
#manager_pw.ldif內(nèi)容
dn: olcDatabase={0}config,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SHA}4QrcOUm6Wau+VuBX8g+IPg==
2. 修改LDAP配置文件
vim cn=config.ldif #修改LDAP配置文件
#cn=config.ldif內(nèi)容
dn: cn=config
changetype: modify
replace: olcLogLevel
olcLogLevel: 4278190079
–
replace: olcDbConfig
olcDbConfig: { “maxSize”: 1073741824, “maxDnInCache”: 500000, “minMetadata”: 0
0320230000, “maxPageSize”: 1000, “checkpoint”: 512023 }
–
add: olcAccess
olcAccess: {0}to * by dn.base=”gidNumber=0+uidNumber=0,cn=peercred,cn=external
auth,cn=unixmen,cn=applications,dc=example,dc=com” manage by * none
–
add: olcAllows
ldapmodify -Y EXTERNAL -H ldapi:/// -f manager_pw.iff #裝載管理員密碼
ldapadd -Y EXTERNAL -H ldapi:/// -f cn=config.ldif #加載配置文件
ldapadd -x -D ‘cn=admin,dc=test,dc=com’ -f ./modules.ldif # 安裝相關(guān)模塊
ldapadd -x -D ‘cn=admin,dc=test,dc=com’ -w password -f schema_base.ldif # 安裝基本模式
ldapadd -x -D ‘cn=admin,dc=test,dc=com’ -w password -f custom_schema.ldif # 安裝自定義模式
Step2:配置LDAP服務(wù)器
完成LDAP服務(wù)器的搭建后,我們需要對LDAP服務(wù)器進行相應(yīng)的配置。LDAP配置文件位于/etc/openldap/ldap.conf下。我們需要將binddn和bindpw設(shè)為LDAP管理員的DN。以管理員用戶cn=admin,dc=test,dc=com為例,可以進行如下設(shè)置:
BASE test.com
URI ldap://myldap.test.com
BIND_DN cn=admin,dc=test,dc=com
BIND_PW password
PORT 389
Step3:同步LDAP用戶
接下來,我們就可以開始同步LDAP用戶了。在LDAP服務(wù)器上,使用ldapadd命令添加用戶信息(下面以一個普通用戶為例):
ldapadd -x -D “cn=admin,dc=test,dc=com” -w “password”
dn: uid=liuwei,ou=People,dc=test,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: liuwei
sn: liu
givenName: wei
uid: liuwei
ml: liuwei@test.com
userPassword: {CRYPT}password
loginShell: /bin/bash
uidNumber: 1029
gidNumber: 1029
homeDirectory: /home/liuwei
shadowExpire: -1
shadowFlag: 0
shadowWarning: 7
shadowMin: 8
shadowMax: 999999
shadowLastChange: 11142
EOF
在完成向LDAP服務(wù)器添加用戶之后,我們需要在其他服務(wù)器上進行LDAP用戶的同步。同步的時候我們需要使用nslcd服務(wù),配置/etc/nslcd.conf文件,使nslcd連接到LDAP服務(wù)器并同步用戶信息。
# /etc/nslcd.conf, nslcd configuration file.
#
# See nslcd.conf(5) for detls.
# The user and group nslcd should run as.
uid nslcd
gid ldap
# The uri pointing to the LDAP server to use for name lookups.
# Multiple entries may be specified.
uri ldap://myldap.test.com
# The search base that will be used for all queries.
base dc=test,dc=com
# SSL options
#ssl on
#ssl start_tls
#tls_reqcert never
# The LDAP version to use.
ldap_version 3
# The distinguished name of the search user.
binddn cn=admin,dc=test,dc=com
bindpw password
# The directory where the runtime data will be stored.
# This directory should be mode 0700, owned by nslcd:nslcd.
#runtime_dir /var/run/nslcd
# The location at which the LDAP server will read the configuration.
# This file should be mode 0640, owned by an unprivileged user and
# should contn credentials for binding the server, etc.
#rootpwmoddn cn=admin,dc=test,dc=com
#rootpwmodpw password
#nslcd_params -d
完成以上步驟即可完成LDAP用戶的同步,我們可以在其他服務(wù)器上通過命令行或者web管理界面查詢到剛剛添加的用戶信息。
3、
通過此篇文章,我們了解到了如何利用LDAP服務(wù)器實現(xiàn)Linux用戶的同步。在實際應(yīng)用中,這種技術(shù)可以大大提高企業(yè)系統(tǒng)的穩(wěn)定性和安全性。希望此篇文章對您有所幫助。
相關(guān)問題拓展閱讀:
- ldap 認證samba 后,密碼同步麻煩請教!
- 如何將域用戶導(dǎo)入linux中
- 如何在Linux下通過ldapsearch查詢活動目錄的內(nèi)容
ldap 認證samba 后,密碼同步麻煩請教!
samba其實可以改驗證方式,不要自己的數(shù)據(jù)庫,直接用系統(tǒng)的密碼
如何將域用戶導(dǎo)入linux中
1.配置DNS
# vi /etc/resolv.conf
nameserver 192.168.2.30
nameserver 192.168.2.32
禪寬# vi /etc/host.conf
# nslookup 192.168.2.32 DNS查找
# net time SET 192.168.2.32 時間同步,客戶端以服務(wù)器時間為嘩旁準
2.samba
首先確亂襲橡保Linux系統(tǒng)中安裝了samba包,并用下述命令來檢查samba包的基礎(chǔ)庫支持,一般的RPM安裝都不會有問題。
# bd -b | grep LDAP
HAVE_LDAP_H
如何在Linux下通過ldapsearch查詢活動目錄的內(nèi)容
從Win2023開始.微軟拋棄NT域而采用活動目錄來管理Windows域.而活動目錄就是微軟基于遵守LDAP協(xié)議的目錄服務(wù).如果用掃描器掃描的話可以發(fā)現(xiàn)活動目錄的389端擾滲口是打開的.而且微軟雖然對這個協(xié)議都擅自作了些改動.但都集中在Replication等同步的部分.其他的部分是基本和其他產(chǎn)品兼容的.所以ldapsearch工具可以順利的搜索AD中的記錄.其實AD最緩洞脊大的客戶就是微軟自己.所以在服務(wù)器配置向?qū)е胁庞肈C作為正式的名稱.AD這個名稱反而次要.AD在配置好之顫笑后就有了健全的目錄樹結(jié)構(gòu).AD的用戶的objectclass為User,默認的用戶記錄位于Users下,而Users的objectclass就是Container.這樣一個AD用戶的DN可能是”cn=username,cn=users,dc=domain-suffix”.AD默認的安全策略不允許”空”綁定(既bind(“”等DN為空的一系列綁定函數(shù)).所以必需要有合法驗證的綁定才行:
ldapsearch -x -W -D “cn=username,cn=users,dc=domain-suffix” -b “basedn” -h host
或者是
ldap search -x -w cred -D “cn=username,cn=users,dc=domain-suffix” -b “basedn” -h host
其中-x對應(yīng)API中的iple_bind*().-w/-W 表示需要密碼 -D “綁定的DN” -b “開始搜索的DN” -h 接主機的IP或者域名.
舉例:我在學(xué)校有一臺實驗用的主機troy配置為”osdn.zzti.edu.cn”主域控制器.假如我在我裝有fedora的筆記本osiris上執(zhí)行l(wèi)dapsearch,命令如下:
ldapsearch -x -W -D “cn=administrator,cn=users,dc=osdn,dc=zzti,dc=edu,dc=cn” -b “cn=administrator,cn=users,dc=osdn,dc=zzti,dc=edu,dc=cn” -h troy.osdn.zzti.edu.cn
這樣就回返回用戶administrator的信息:
# extended LDIF
#
# LDAPv3
# base ; with scope sub
# filter: (objectclass=*)
# requesting: ALL
#
# Administrator, Users, osdn.zzti.edu.cn
dn: CN=Administrator,CN=Users,DC=osdn,DC=zzti,DC=edu,DC=cn
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: Administrator
description:: 566h55CG6K6h566X5py6KOWfnynnmoTlhoXnva7luJDmiLc=
distinguishedName: CN=Administrator,CN=Users,DC=osdn,DC=zzti,DC=edu,DC=cn
instanceType: 4
whenCreated:8.0Z
whenChanged:4.0Z
uSNCreated: 8194
memberOf: CN=Group Policy Creator Owners,CN=Users,DC=osdn,DC=zzti,DC=edu,DC=cn
memberOf: CN=Domain Admins,CN=Users,DC=osdn,DC=zzti,DC=edu,DC=cn
memberOf: CN=Enterprise Admins,CN=Users,DC=osdn,DC=zzti,DC=edu,DC=cn
memberOf: CN=Schema Admins,CN=Users,DC=osdn,DC=zzti,DC=edu,DC=cn
memberOf: CN=Administrators,CN=Builtin,DC=osdn,DC=zzti,DC=edu,DC=cn
uSNChanged: 13895
name: Administrator
objectGUID:: z44SriNF40SGBgQson8RtA==
userAccountControl: 66048
badPwdCount: 0
codePage: 0
countryCode: 0
badPasswordTime:37500
lastLogoff: 0
lastLogon:43750
pwdLastSet:00000
primaryGroupID: 513
objectSid:: AQUAAAAAAAUVAAAAfA5HVz/NVF7R0u429AEAAA==
adminCount: 1
accountExpires:775807
logonCount: 17
sAMAccountName: Administrator
sAMAccountType:
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=osdn,DC=zzti,DC=edu,DC
=cn
isCriticalSystemObject: TRUE
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
ldap linux用戶 同步的介紹就聊到這里吧,感謝你花時間閱讀本站內(nèi)容,更多關(guān)于ldap linux用戶 同步,Linux LDAP用戶同步實現(xiàn),ldap 認證samba 后,密碼同步麻煩請教!,如何將域用戶導(dǎo)入linux中,如何在Linux下通過ldapsearch查詢活動目錄的內(nèi)容的信息別忘了在本站進行查找喔。
成都服務(wù)器托管選創(chuàng)新互聯(lián),先上架開通再付費。
創(chuàng)新互聯(lián)(www.cdcxhl.com)專業(yè)-網(wǎng)站建設(shè),軟件開發(fā)老牌服務(wù)商!微信小程序開發(fā),APP開發(fā),網(wǎng)站制作,網(wǎng)站營銷推廣服務(wù)眾多企業(yè)。電話:028-86922220
網(wǎng)頁標題:Linux LDAP用戶同步實現(xiàn) (ldap linux用戶 同步)
文章出自:http://www.dlmjj.cn/article/cosphsj.html


咨詢
建站咨詢
