Uuntu 20.04 install OpenLDAP
一、參考
- 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服務端
# 下載軟件 apt-get update apt-get install slapd ldap-utils -y# 配置slapd
dpkg-reconfigure slapd
- 1
- 2
- 3
- 4
- 5
- 6
# 安裝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登陸界面中自動填寫的用戶名(cn=admin,dc=hive,dc=lan),可用//注釋掉。信息可看命令slapcat的輸出。 $servers->setValue('auto_number','min',array('uidNumber'=>10000,'gidNumber'=>10000)); # 改下 $config->custom->appearance['hide_template_warning'] = true; # 改下# 關閉apache的默認界面
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. 添加組
同樣的方法創建一個cn=users。
5. 創建用戶
直接填寫last name就可以了——其他相關項會自動填寫。
這里Login shell配置界面只支持/bin/sh。在Ubuntu20中/bin/sh -> dash,不是bash。
所以用戶ssh登陸之后是不執行.bashrc的。這導致用戶登陸后命令行提示符為$,且不支持命令行補全,不支持history,不支持顏色顯示等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
注意上圖兩個cn=test01是顯示問題,刷新或者logout再login就顯示正常了。
此外,可以驗證用戶的密碼。
6. LDAP客戶端配置
- 安裝客戶端軟件包
- 1
- 2
- 進入設置界面
可以使用多個URI(使用空格分割)指向多臺LDAP服務器,以備不測。盡量使用IP地址,防止DNS解析故障造成的問題。
這里要把ldapi:///更改為ldap://ip
相關的配置在/etc/ldap.conf文件中。
可以使用如下方式對上述配置進行微調(optional)
英語中optional更傾向于不選擇。
dpkg-reconfigure nslcd dpkg-reconfigure ldap-auth-config- 1
- 2
- 配置/etc/nsswitch.conf增加ldap的認證
- 1
- 2
- 3
- 4
- 更新PAM配置
- 1
更新時如下選擇
家目錄中會拷貝bash的模版文件/etc/skel/
- 1
- 2
- 重啟客戶端服務
- 1
此時使用ssh登陸一下LDAP客戶端測試看看。
三、在LDAP服務器端配置用戶
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服務器端通過命令行配置用戶
- 創建包含users和groups信息的ou(organizational unit)
vim /your/path/users-ou.ldif
dn: ou=animals,dc=bee,dc=com objectClass: organizationalUnit objectClass: top ou: animalsdn: 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的對應。
- 修改SLAPD數據庫的訪問控制
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的對應。
- 更新LDAP數據庫的訪問控制列表
- 1
- 使用ou信息更新數據庫
- 1
- 新增一個新用戶賬號
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: 0dn: 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
- 添加新用戶
- 1
- 為用戶設置密碼
- 1
uid為用戶名,組織單元ou改為你的,dc=bee,dc=com對應你的域名domain(bee.com)。
可以使用如下命令產生密碼的哈希:
- 1
- 2
- 3
- 4
記錄回顯的哈希值。
- 創建新用戶
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}處。
- 添加新用戶到數據庫
- 1
四、使用TCP Wrappers保護LDAP服務
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總結
以上是生活随笔為你收集整理的Uuntu 20.04 install OpenLDAP的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 人脸识别基础关键技术
- 下一篇: Ubuntu20.04 安装qq和微信