书接上文:LDAP启动TLS 完整操做流程html
基础环境:Ubuntu18.04ios
root@cky:~# apt install samba smbldap-tools -y
查看版本git
root@cky:~# dpkg -l samba smbldap-tools Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-===============================================-============================-============================-=================================================================================================== ii samba 2:4.7.6+dfsg~ubuntu-0ubuntu2 amd64 SMB/CIFS file, print, and login server for Unix ii smbldap-tools 0.9.9-1ubuntu3 all Scripts to manage Unix and Samba accounts stored on LDAP
为了将OpenLDAP用做Samba的后端,DIT将须要使用能够正确描述Samba数据的属性。能够经过引入Samba LDAP模式得到此类属性。github
该模式位于如今安装的samba软件包中,而且已经采用ldif格式。shell
拷贝samba.schema
和 samba.ldif
ubuntu
找不到samba.schema
,从源码搞了一份(git clone https://github.com/samba-team/samba.git
)后端
cp /usr/share/doc/samba/examples/LDAP/samba.ldif.gz /etc/ldap/schema cp /root/cky/samba/samba-4.7.6+dfsg~ubuntu/examples/LDAP/samba.schema /etc/ldap/schema/ root@cky:/etc/ldap/schema# pwd /etc/ldap/schema root@cky:/etc/ldap/schema# gzip -d samba.ldif.gz
导入:api
root@cky:/etc/ldap/schema# ldapadd -Q -Y EXTERNAL -H ldapi:/// -f samba.ldif adding new entry "cn=samba,cn=schema,cn=config"
要查询和查看此新架构:bash
ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config 'cn=*samba*'
既然slapd知道了Samba属性,咱们就能够基于它们创建一些索引。索引条目是客户端对DIT执行筛选搜索时提升性能的一种方法。服务器
建立samba_indices.ldif
具备如下内容的文件:
root@cky:~/ldap# pwd /root/ldap root@cky:~/ldap# cat samba_indices.ldif dn: olcDatabase={1}mdb,cn=config changetype: modify replace: olcDbIndex olcDbIndex: objectClass eq olcDbIndex: uidNumber,gidNumber eq olcDbIndex: loginShell eq olcDbIndex: uid,cn eq,sub olcDbIndex: memberUid eq,sub olcDbIndex: member,uniqueMember eq olcDbIndex: sambaSID eq olcDbIndex: sambaPrimaryGroupSID eq olcDbIndex: sambaGroupType eq olcDbIndex: sambaSIDList eq olcDbIndex: sambaDomainName eq olcDbIndex: default sub,eq
使用ldapmodify
实用程序加载新索引:
root@cky:~/ldap# ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f samba_indices.ldif modifying entry "olcDatabase={1}mdb,cn=config"
若是正常到如今,能够使用ldapsearch
查看到新索引:
root@cky:~/ldap# ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config olcDatabase={1}mdb olcDbIndex dn: olcDatabase={1}mdb,cn=config olcDbIndex: objectClass eq olcDbIndex: uidNumber,gidNumber eq olcDbIndex: loginShell eq olcDbIndex: uid,cn eq,sub olcDbIndex: memberUid eq,sub olcDbIndex: member,uniqueMember eq olcDbIndex: sambaSID eq olcDbIndex: sambaPrimaryGroupSID eq olcDbIndex: sambaGroupType eq olcDbIndex: sambaSIDList eq olcDbIndex: sambaDomainName eq olcDbIndex: default sub,eq
接下来,配置smbldap-tools软件包以匹配您的环境。该软件包带有一个名为smbldap-config的配置帮助程序脚本。可是,在运行它以前,您应该肯定如下两个重要的配置设置/etc/samba/smb.conf
:
# file : /etc/samba/smb.conf [global] workgroup = Company server string = Samba Server Version %v log file = /var/log/samba/log.%m security = user passdb backend = ldapsam:ldap://company02.com ldap suffix = dc=company,dc=com ldap user suffix = ou=Dev ldap group suffix = ou=Group ldap machine suffix = ou=Computers ldap idmap suffix = ou=Idmap ldap admin dn = cn=admin,dc=company,dc=com ldap ssl = start tls ldap passwd sync = yes
Note: ubuntu官方文档的 ldap ssl = start tls
可是设置该项后重启服务报ERROR:Failed to issue the StartTLS instruction: Protocol error
测试一下samba
配置文件
root@cky:~/ldap# testparm -s
经过运行配置脚原本继续生成smbldap-tools配置
root@cky:~/ldap# smbldap-config # 只有这三项进行了输入操做,别的都是直接回车 netbios name [] > Company ldap master bind password [] > 654321 ldap slave bind password [] > 654321
使用smbldap-populate
添加Samba所需的LDAP对象。它将询问您“域根”用户的密码,该用户也是LDAP中存储的“根”用户:
root@cky:~# smbldap-populate -g 10003 -u 10003 -r 10003 Populating LDAP directory for domain Company (S-1-5-21-385293779-2563394074-3374145406) (using builtin directory structure) entry dc=company,dc=com already exist. entry ou=Dev,dc=company,dc=com already exist. entry ou=Groups,dc=company,dc=com already exist. adding new entry: ou=Computers,dc=company,dc=com adding new entry: ou=Idmap,dc=company,dc=com adding new entry: sambaDomainName=Company,dc=company,dc=com adding new entry: uid=root,ou=Dev,dc=company,dc=com adding new entry: uid=nobody,ou=Dev,dc=company,dc=com adding new entry: cn=Domain Admins,ou=Groups,dc=company,dc=com adding new entry: cn=Domain Users,ou=Groups,dc=company,dc=com adding new entry: cn=Domain Guests,ou=Groups,dc=company,dc=com adding new entry: cn=Domain Computers,ou=Groups,dc=company,dc=com adding new entry: cn=Administrators,ou=Groups,dc=company,dc=com adding new entry: cn=Account Operators,ou=Groups,dc=company,dc=com adding new entry: cn=Print Operators,ou=Groups,dc=company,dc=com adding new entry: cn=Backup Operators,ou=Groups,dc=company,dc=com adding new entry: cn=Replicators,ou=Groups,dc=company,dc=com Please provide a password for the domain root: Changing UNIX and samba passwords for root New password: 654321 Retype new password: 654321 New passwords don't match!
将rootDN用户的密码(在slapd软件包的安装过程当中设置的密码)告知Samba:
root@cky:~# smbpasswd -W Setting stored password for "cn=admin,dc=company,dc=com" in secrets.tdb New SMB password: 654321 Retype new SMB password: 654321
为了让LDAP用户可以链接到samba并进行身份验证的最后一步,如今须要这些用户也以“ unix”用户身份出如今系统中。
安装sssd-ldap
root@cky:~# apt -y install sssd-ldap
配置/etc/sssd/sssd.conf
[sssd] config_file_version = 2 domains = Company [domain/Company] id_provider = ldap auth_provider = ldap ldap_uri = ldap://192.168.3.188 cache_credentials = True ldap_search_base = dc=company,dc=com
调整权限并启动服务
root@cky:~# chmod 0600 /etc/sssd/sssd.conf root@cky:~# chown root:root /etc/sssd/sssd.conf root@cky:~# systemctl restart sssd
从新启动Samba服务:
root@cky:~# systemctl restart smbd.service nmbd.service
要快速测试设置,查看getent是否能够列出Samba组:
root@cky:~# getent group Replicators root@cky:~#
有问题,查询不到用户组???一个大坑
仍是认证有问题,系统中ldap
的用户查不到
google+百度 良久,外带牺牲了8根秀发,通过N多尝试以后,我发现如下方法便可解决:
修改配置文件/etc/nsswitch.conf
passwd: compat systemd sss ldap db group: compat systemd sss ldap db shadow: compat sss ldap db
主要就是这三项后面加了 ldap
和 db
安装nslcd
root@cky:~# apt install nslcd -y
修改配置文件/etc/nslcd.conf
root@cky:~# grep -Ev '^$|^[#;]' /etc/nslcd.conf uid nslcd gid nslcd uri ldapi:///192.168.3.188 base dc=company,dc=com ldap_version 3 binddn cn=admin,dc=company,dc=com bindpw 654321 ssl off tls_cacertfile /etc/ssl/certs/ca-certificates.crt
重启nslcd
服务
root@cky:~# systemctl restart nslcd root@cky:~# systemctl enable nslcd nslcd.service is not a native service, redirecting to systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable nslcd
重启slapd
服务
root@cky:~# systemctl restart slapd
再次查询
root@cky:~# getent group Replicators Replicators:*:552:
因此我也不知道是我看的不够全,仍是官方文档的缺失,此处再次diss一下Ubuntu官方文档
smbldap-tools
管理用户、组和计算机帐户启用自动主目录建立:
root@cky:~# pam-auth-update --enable mkhomedir
要添加具备主目录的新用户:
root@cky:~# smbldap-useradd -a -P -m ldap_user01 Changing UNIX and samba passwords for ldap_user01 New password: 111111 Retype new password: 111111
查一下ldap
中的用户
root@cky:~# ldapsearch -x -b "uid=ldap_user01,ou=Dev,dc=company,dc=com"
看一下home
目录
root@cky:~# ls /home cky ldap_user01
使用getent
查询一下用户
root@cky:~# getent passwd ldap_user01 ldap_user01:x:10003:513:System User:/home/ldap_user01:/bin/bash