日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Uuntu 20.04 install OpenLDAP

發(fā)布時(shí)間:2025/7/25 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Uuntu 20.04 install OpenLDAP 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、參考

  • https://www.techrepublic.com/article/how-to-install-openldap-and-phpldapadmin-on-ubuntu-server-20-04/
  • https://blog.csdn.net/lodianm/article/details/105386314(主要參考)
  • https://www.jianshu.com/p/e6de94d15d47

二、安裝OpenLDAP和phpLDAPadmin

1. 安裝OpenLDAP服務(wù)端

# 下載軟件 apt-get update apt-get install slapd ldap-utils -y

# 配置slapd
dpkg-reconfigure slapd

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6






# 查看配置結(jié)果 slapcat

# 安裝apache
apt install apache2

  • 1
  • 2
  • 3
  • 4
  • 5

2. 安裝phpLDAPadmin

# 安裝 apt-get install phpldapadmin -y # 配置 vim /etc/phpldapadmin/config.php ================================================================== $servers->setValue('server','name','My LDAP Server'); # 不用改 $servers->setValue('server','host','127.0.0.1'); # 不用改 $servers->;setValue('server','base',array('dc=hive,dc=lan')); # hive和lan(hive.lan)改成你的 $servers->setValue('login','auth_type','session'); # 不用改 $servers->setValue('login','bind_id','cn=admin,dc=hive,dc=lan'); # WEB登陸界面中自動(dòng)填寫的用戶名(cn=admin,dc=hive,dc=lan),可用//注釋掉。信息可看命令slapcat的輸出。 $servers->setValue('auto_number','min',array('uidNumber'=>10000,'gidNumber'=>10000)); # 改下 $config->custom->appearance['hide_template_warning'] = true; # 改下

# 關(guān)閉apache的默認(rèn)界面
a2dissite 000-default.conf
systemctl restart apache2

# 登陸管理頁面
http://SERVER_IP/phpldapadmin
# username形如cn=admin,dc=hive,dc=lan
# 輸入你的admin password

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21



3. 添加組織單位



4. 添加組





同樣的方法創(chuàng)建一個(gè)cn=users。

5. 創(chuàng)建用戶



直接填寫last name就可以了——其他相關(guān)項(xiàng)會(huì)自動(dòng)填寫。

這里L(fēng)ogin shell配置界面只支持/bin/sh。在Ubuntu20中/bin/sh -> dash,不是bash。
所以用戶ssh登陸之后是不執(zhí)行.bashrc的。這導(dǎo)致用戶登陸后命令行提示符為$,且不支持命令行補(bǔ)全,不支持history,不支持顏色顯示等bash特性。這時(shí)可以運(yùn)行bash即可:

$ bash
  • 1

或者可以修改/etc/phpldapadmin/templates/creation/posixAccount.xml

<attribute id="loginShell"><display>Login shell</display><order>9</order><page>1</page><!-- <value><![CDATA[=php.PickList(/;(&(objectClass=posixAccount));loginShell;%loginShell%;;;;loginShell)]]></value> --><type>select</type><value id="/bin/sh">/bin/sh</value><value id="/bin/csh">/bin/csh</value><value id="/bin/tsh">/bin/tsh</value><value id="/bin/bash">/bin/bash</value> 在這里新增/bin/bash條目 </attribute>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11



注意上圖兩個(gè)cn=test01是顯示問題,刷新或者logout再login就顯示正常了。
此外,可以驗(yàn)證用戶的密碼。

6. LDAP客戶端配置

  • 安裝客戶端軟件包
apt-get update apt-get install ldap-utils libpam-ldap libnss-ldap nslcd
  • 1
  • 2
  • 進(jìn)入設(shè)置界面

    可以使用多個(gè)URI(使用空格分割)指向多臺(tái)LDAP服務(wù)器,以備不測。盡量使用IP地址,防止DNS解析故障造成的問題。


    這里要把ldapi:///更改為ldap://ip
    相關(guān)的配置在/etc/ldap.conf文件中。





可以使用如下方式對(duì)上述配置進(jìn)行微調(diào)(optional)

英語中optional更傾向于不選擇。

dpkg-reconfigure nslcd dpkg-reconfigure ldap-auth-config
  • 1
  • 2
  • 配置/etc/nsswitch.conf增加ldap的認(rèn)證
passwd: files systemd ldap group: files systemd ldap shadow: files ldap gshadow: files ldap
  • 1
  • 2
  • 3
  • 4
  • 更新PAM配置
pam-auth-update
  • 1

更新時(shí)如下選擇

家目錄中會(huì)拷貝bash的模版文件/etc/skel/

$ ls -a /etc/skel/ . .. .bash_logout .bashrc .profile
  • 1
  • 2
  • 重啟客戶端服務(wù)
systemctl restart nslcd nscd
  • 1

此時(shí)使用ssh登陸一下LDAP客戶端測試看看。

三、在LDAP服務(wù)器端配置用戶

1. 在phpLDAPadmin界面中更改用戶密碼


然后commit即可。

2. LDIF配置文件

  • LDIF文件為何物
    http://blog.chinaunix.net/uid-30540544-id-5284844.html
    https://www.openldap.org/doc/admin24/backends.html#LDIF
  • LDIF文件格式
    http://blog.chinaunix.net/uid-30540544-id-5288795.html
    或者使用命令man ldif查看
  • 密碼策略的配置
    https://www.openldap.org/doc/admin24/overlays.html#Password%20Policies

3. 在LDAP服務(wù)器端通過命令行配置用戶

  • 創(chuàng)建包含users和groups信息的ou(organizational unit)

vim /your/path/users-ou.ldif

dn: ou=animals,dc=bee,dc=com objectClass: organizationalUnit objectClass: top ou: animals

dn: ou=zoo,dc=bee,dc=com
objectClass: organizationalUnit
objectClass: top
ou: zoo

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

將dc=bee,dc=com改成你domain的對(duì)應(yīng)。

  • 修改SLAPD數(shù)據(jù)庫的訪問控制

vim /your/path/update-mdb-acl.ldif

n: olcDatabase={1}mdb,cn=config changetype: modify replace: olcAccess olcAccess: to attrs=userPassword,shadowLastChange,shadowExpireby self writeby anonymous authby dn.subtree="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manageby dn.exact="cn=readonly,ou=animals,dc=bee,dc=com" readby * none olcAccess: to dn.exact="cn=readonly,ou=animals,dc=bee,dc=com" bydn.subtree="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage by * none olcAccess: to dn.subtree="dc=bee,dc=com" by dn.subtree="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manageby users readby * none
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

將dc=bee,dc=com改成你domain的對(duì)應(yīng)。

  • 更新LDAP數(shù)據(jù)庫的訪問控制列表
ldapadd -Y EXTERNAL -H ldapi:/// -f update-mdb-acl.ldif
  • 1
  • 使用ou信息更新數(shù)據(jù)庫
ldapadd -Y EXTERNAL -H ldapi:/// -f users-ou.ldif
  • 1
  • 新增一個(gè)新用戶賬號(hào)
    uid就是用戶名

vim /your/path/user.ldif

dn: uid=tiger,ou=animals,dc=bee,dc=com objectClass: inetOrgPerson objectClass: posixAccount objectClass: shadowAccount uid: tiger cn: tiger sn: tigerman loginShell: /bin/bash uidNumber: 10000 gidNumber: 10000 homeDirectory: /home/tiger shadowMax: 60 shadowMin: 1 shadowWarning: 7 shadowInactive: 7 shadowLastChange: 0

dn: cn=tiger,ou=zoo,dc=bee,dc=com
objectClass: posixGroup
cn: tiger
gidNumber: 10000
memberUid: tiger

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 添加新用戶
ldapadd -Y EXTERNAL -H ldapi:/// -f user.ldif
  • 1
  • 為用戶設(shè)置密碼
ldappasswd -H ldapi:/// -Y EXTERNAL -S "uid=tiger,ou=animals,dc=bee,dc=com"
  • 1

uid為用戶名,組織單元ou改為你的,dc=bee,dc=com對(duì)應(yīng)你的域名domain(bee.com)。
可以使用如下命令產(chǎn)生密碼的哈希:

$ slappasswd New password: Re-enter new password: {SSHA}0MP6O2gKZLeqXhCjQwTQWBtc3S3EZtoT
  • 1
  • 2
  • 3
  • 4

記錄回顯的哈希值。

  • 創(chuàng)建新用戶

vim /your/path/readonly-user.ldif

dn: cn=readonly,ou=animals,dc=bee,dc=com objectClass: organizationalRole objectClass: simpleSecurityObject cn: readonly userPassword: {SSHA}0MP6O2gKZLeqXhCjQwTQWBtc3S3EZtoT description: Bind DN user for LDAP Operations
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

用你記錄的哈希值替換上邊的{SSHA}處。

  • 添加新用戶到數(shù)據(jù)庫
ldapadd -Y EXTERNAL -H ldapi:/// -f readonly-user.ldif
  • 1

四、使用TCP Wrappers保護(hù)LDAP服務(wù)

https://www.openldap.org/doc/admin24/security.html#TCP%20Wrappers

vim /etc/hosts.allow

slapd: 10.0.0.0/255.0.0.0 127.0.0.1 : ALLOW slapd: ALL : DENY

總結(jié)

以上是生活随笔為你收集整理的Uuntu 20.04 install OpenLDAP的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。