Ubuntu 16.04 配置LDAP并配置samba 使用Ldap认证

本文仅列出主要步骤,其他细节请参考ubuntu指南
一 首先找一台主机配置LDAP.
LDAP 配置比较简单
1 apt install slapd ldap-tools
配置文件/etc/ldap/ldap.conf
2 dpkg-reconfigure slapd 可以利用此命令重配置db参数

3 安装完后,开始安装管理包
apt install ldapscripts
常用管理命令
Ldapadduser user group
Ldapsetpasswd user
Ldapaddgroup group
Ldapdeleteuser ldapdeleteuserfromgroup user group
Ldapmodifyuser kkk
4 到此即可使用,当然你可安装phpmyldap之类可视化管理

5 如配置samba使用ldap认证,需在LDAP主机上运行如下命令
首先导入schema

    Zcat /usr/share/doc/samba/examples/LDAP/samba.ldif.gz | ldapadd -Q -Y EXTERNAL -H ldapi:///
 Samba indices 可以导入,只是改善性能
Apt install libnss-ldap
     Dpkg-reconfigure ldap-auth-config
     Auth-client-config -t nss -p lac_ldap
  Pam-auth-update 

补充一下ldap备份命令
slapcat -n 0 > config.ldif
slapcat -n 1 > example.com.ldif

新的ldap导入配置文件
Systemctl stop slapd.service
Mkdir /var/lib/ldap/accesslog
Slapadd -F /etc/ldap/slapd.d -n 0 -l /config.ldif
Slapadd -F /etc/ldap/slapd.d -n 1 -l /example.com.ldif
Slapadd -F /etc/ldap/slapd.d -n 2 -l /access.ldif
Chown -R openldap:openldap /etc/ldap/slapd.d /var/lib/ldap
Systemctl start slapd.service

二 SAMBA 配置
Apt install samba smbldap-tools
Smbldap-config 必须samba 启动才可配置 必须先配置
修改配置文件 /etc/samba/smb.conf
基本配置
Passdb backend = ldapsam:ldap 具体ip
Ldap suffix =
Ldap user suffix =
Ldap group suffix =
Ldap machine suffix = 可不用
Ldap idmap suffix = 可不用
Ldap admin dn = cn= ,dc=,dc= 和你配置ldap的一致
Ldap ssl = off 否则默认打开tls ,会log出错但不影响
Ldap passwd sync =yes

配置完可以通过一下命令测试
Smbpasswd -W 赋予ldap 管理员密码 很重要,否则不初始链接ldap
至此samba已经可以通过ldap来认证管理用户了

增加其他管理包
Apt install libnss-ldap
Auth-client-config -t nss -p lac_ldap
Systemctl restart smbd nmbd
如成功 用ldap认证,执行以下会有显示结果
Net getlocalsid
sambaSid
sambaDomainName=SMB,DC=,DC=

Vi /usr/share/perl5/smbldap_tools.pm
#!/usr/bin/perl

Smb主机增加用户至ldap
首先ldap增加sambaUnixIDPool属性 ,填写起始gid,uid
Smbldap-groupadd -a xxx
Smbldap-useradd -a aaa -g xxx 增加为ldap上访问此samba用户
Smbldap-userlist,grouplist

猜你喜欢

转载自blog.csdn.net/CSDN1887/article/details/81538945
今日推荐