https://computingforgeeks.com/install-and-configure-openldap-server-ubuntu/
https://www.techrepublic.com/article/how-to-install-openldap-on-ubuntu-18-04/
请注意你需要把ellis.ldap.com 换成你想要的域名或者正确的域名
- 设置hostname
sudo hostnamectl set-hostname ellis.ldap.com
- 修改host文件
sudo vim /etc/hosts
192.168.214.131 ellis.ldap.com
- Install OpenLDAP Server on Ubuntu 22.04|20.04|18.04
sudo apt update
sudo apt -y install slapd ldap-utils
安装过程中会提示你设置ldap的admin 密码
- 运行以下命令,确认安装成功
sudo slapcat
显示如下
dn: dc=ldap,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
o: ldap.com
dc: ldap
structuralObjectClass: organization
entryUUID: 65094458-6ab7-103c-8f95-cd21456a8e2a
creatorsName: cn=admin,dc=ldap,dc=com
createTimestamp: 20220518053038Z
entryCSN: 20220518053038.430451Z#000000#000#000000
modifiersName: cn=admin,dc=ldap,dc=com
modifyTimestamp: 20220518053038Z
- Add base dn for Users and Groups
The next step is adding a base DN for users and groups. Create a file named basedn.ldif with below contents:
vim basedn.ldif
dn: ou=people,dc=ldap,dc=com
objectClass: organizationalUnit
ou: people
dn: ou=groups,dc=ldap,dc=com
objectClass: organizationalUnit
ou: groups
请将ldap 以及com 替换成你的
Now add the file by running the command:
ldapadd -x -D cn=admin,dc=ldap,dc=com -W -f basedn.ldif
- 添加用户以及group
Generate a password for the user account to add.
sudo slappasswd
vim ldapusers.ldif
dn: uid=ellis,ou=people,dc=ldap,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: ellis
sn: ellis
givenName: ellis
cn: ellis
displayName: ellis
uidNumber: 10000
gidNumber: 5000
userPassword: {SSHA}ms3WJkFGn7T4sf8t59pgHqtmn2rnyVQU
gecos: FULLNAME
loginShell: /bin/bash
homeDirectory: /home/ellis
Replace computingforgeeks with the username to add
dc=ldap,dc=com with your correct domain values.
cn & sn with your Username Values
{SSHA}Zn4/E5f+Ork7WZF/alrpMuHHGufC3x0k with your hashed password
DEPARTMENT is a department or group you want to add.
SUBGROUP is a sub-group of the department.
USER is an actual user account on your system.
LASTNAME is the last name of the user.
FIRSTNAME is the first name of the user.
FULLNAME is the full name of the user.
DISPLAYNAME is the name you want displayed for the user.
USERDIRECTORY is the user’s home directory on the Linux server.
添加用户
ldapadd -x -D cn=admin,dc=ldap,dc=com -W -f ldapusers.ldif
Do the same of group. Create ldif file:
vim ldapgroups.ldif
dn: cn=ellis,ou=groups,dc=ldap,dc=com
objectClass: posixGroup
cn: ellis
gidNumber: 1000
memberUid: ellis
添加group
ldapadd -x -D cn=admin,dc=ldap,dc=com -W -f ldapgroups.ldif