Samba通过Openldap统一认证
1.环境准备
1.1、实验环境
[root@moban ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@moban ~]# uname -r
2.6.32-642.el6.x86_64
1.2、校准服务器时间
[root@moban ~]# ntpdate pool.ntp.org
12 Nov 01:11:59 ntpdate[2354]: adjust time server 202.118.1.81 offset 0.004307 sec
[root@moban ~]# crontab -l
#time sync
*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
1.3、关闭selinux和iptables
[root@moban ~]# getenforce
Enforcing
[root@moban ~]# setenforce 0
[root@moban ~]# getenforce
Permissive
[root@moban ~]# service iptables stop
2.Openldap和Samba的安装配置
2.1、安装Openldap和Samba
[root@moban ~]# yum -y install openldap openldap-clients openldap-servers nss-pam-ldapd
[root@moban ~]# yum -y install samba-common samba samba-client
2.2、配置openldap
a.Openldap引用samba.schema
[root@moban ~]# cp /usr/share/doc/samba-3.6.23/LDAP/samba.schema /etc/openldap /schema/
b.拷贝openldap的示例配置文件
[root@moban ~]# cp /usr/share/openldap-servers/slapd.conf.obsolete /etc/openldap/slapd.conf
c.生成ldap管理员密码
[root@moban ~]# slappasswd -s 123456
{SSHA}Ae1JJTvbeP60y91e9MdAqOmpleSWG19o
d.修改配置文件
[root@moban ~]# vi /etc/openldap/slapd.conf
在18行插入如下内容:
18 include /etc/openldap/schema/samba.schema
注释掉99行到102行:
99 # database config
100 # access to *
101 # by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" manage
102 # by * none
在111行插入如下访问权限内容:
111 access to attrs=userPassword
112 by self write
113 by anonymous auth
114 by * none
115 access to attrs=sambaNTPassword
116 by self write
117 by anonymous auth
118 by * none
119 access to *
120 by self write
121 by * read
修改126行到134行的内容为:
修改前:
126 database bdb
127 suffix "dc=my-domain,dc=com"
128 checkpoint 1024 15
129 rootdn "cn=Manager,dc=my-domain,dc=com"
130 # Cleartext passwords, especially for the rootdn, should
131 # be avoided. See slappasswd(8) and slapd.conf(5) for d
etails.
132 # Use of strong authentication encouraged.
133 # rootpw secret
134 # rootpw {crypt}ijFYNcSNctBYg
修改后:
126 database bdb
127 suffix "dc=etiantian,dc=org"
128 checkpoint 1024 15
129 rootdn "cn=admin,dc=etiantian,dc=org"
130 # Cleartext passwords, especially for the rootdn, should
131 # be avoided. See slappasswd(8) and slapd.conf(5) for d
etails.
132 # Use of strong authentication encouraged.
133 # rootpw secret
134 rootpw {SSHA}Ae1JJTvbeP60y91e9MdAqOmpleSWG19o
修改143行的内容为:
修改前:
index ou,cn,mail,surname,givenname eq,pres,sub
修改后:
index ou,cn,mail,surname,givenname eq,pres,sub,approx
修改105行到109行的内容为:
修改前:
105 database monitor
106 access to *
107 by dn.exact="gidNumber=0+uidNumber=0,cn=peercred,cn
=external,cn=auth" read
108 by dn.exact="cn=Manager,dc=my-domain,dc=com" read
109 by * none
修改后:
105 database monitor
106 access to *
107 by dn.exact="cn=admin,dc=etiantian,dc=org" read
108 by * none
2.3、初始化openldap
a.删除openldap原始的配置文件和数据
[root@moban ~]# rm -rf /etc/openldap/slapd.d/*
[root@moban ~]# rm -rf /var/lib/ldap/*
b.拷贝数据库的配置文件
[root@moban ~]# cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
[root@moban ~]# chown ldap.ldap -R /var/lib/ldap
[root@moban ~]# ll /var/lib/ldap
total 4
-rw-r--r--. 1 ldap ldap 845 Nov 12 01:54 DB_CONFIG
c.生成2.4版本的配置文件
[root@moban ldap]# slaptest -u
config file testing succeeded
[root@moban ldap]# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/ #生成旧版本的配置文件
config file testing succeeded
d.初始化openldap的基础数据
[root@moban openldap]# vi base.ldif
dn: dc=etiantian,dc=org
objectClass: organization
objectClass: dcObject
dc: etiantian
o: etiantian
dn: ou=People,dc=etiantian,dc=org
objectClass: organizationalUnit
ou: People
dn: ou=group,dc=etiantian,dc=org
objectClass: organizationalUnit
ou: group
[root@moban openldap]# vi group.ldif
dn: cn=DBA,ou=group,dc=etiantian,dc=org
objectClass: posixGroup
objectClass: top
cn: DBA
memberUid: test1
gidNumber: 10673
[root@moban openldap]# vi user.ldif
dn: uid=test1,ou=People,dc=etiantian,dc=org
objectClass: posixAccount
objectClass: top
objectClass: inetOrgPerson
objectClass: shadowAccount
gidNumber: 0
givenName: test1
sn: test1
uid: test1
homeDirectory: /home/test1
loginShell: /bin/bash
shadowFlag: 0
shadowMin: 0
shadowMax: 99999
shadowWarning: 0
shadowInactive: 99999
shadowLastChange: 12011
shadowExpire: 99999
cn: test1
uidNumber: 24422
e.把基础数据导入ldap
[root@moban openldap]# slapadd -l base.ldif
58260c66 The first database does not allow slapadd; using the first available one (2)
_#################### 100.00% eta none elapsed none fast!
Closing DB...
[root@moban openldap]# slapadd -l group.ldif
58260c6d The first database does not allow slapadd; using the first available one (2)
_#################### 100.00% eta none elapsed none fast!
Closing DB...
[root@moban openldap]# slapadd -l user.ldif
58260c72 The first database does not allow slapadd; using the first available one (2)
_#################### 100.00% eta none elapsed none fast!
Closing DB...
[root@moban openldap]# chown -R ldap.ldap /var/lib/ldap
[root@moban openldap]# chown -R ldap.ldap /etc/openldap/slapd.d
[root@moban openldap]# chmod -R 700 /var/lib/ldap
[root@moban openldap]# chmod -R 700 /etc/openldap/slapd.d
2.4、配置samba
a.修改samba的配置
[root@moban openldap]# cd /etc/samba/
[root@moban samba]# cp smb.conf smb.conf.ori
[root@moban samba]# vi smb.conf
[global]
workgroup = WORKGROUP
server string = Samba-ldap Server Version %v
netbios name = samba-ldapsam
log file = /var/log/samba/log.%m
max log size = 50
security = user
passdb backend = ldapsam:ldap://192.168.0.111/
ldap suffix = "dc=etiantian,dc=org"
ldap admin dn = "cn=admin,dc=etiantian,dc=org"
ldap user suffix = "ou=People,dc=etiantian,dc=org"
ldap group suffix = "ou=group,dc=etiantian,dc=org"
ldap delete dn = no
ldap passwd sync = yes
ldap ssl = no
[sambashare]
comment = share all
path = /app/log
browseable = yes
public = yes
writable = yes
[myshare]
comment = share for users
path = /application
browseable = yes
public = no
writable = yes
b.创建共享数据目录
[root@moban samba]# mkdir /app/log -p
[root@moban samba]# mkdir /application
提示:为了方便测试,先给目录777的权限
[root@moban samba]# chmod -R 777 /application
[root@moban samba]# chmod -R 777 /app/log
c.保存openldap的admin密码到samba中
提示:为了使samba能够访问ldap,把ldap管理员的密码保存到samba的secrets.tdb中(/var/lib/samba/private/secrets.tdb)
[root@moban samba]# smbpasswd -w 123456
Setting stored password for "cn=admin,dc=etiantian,dc=org" in secrets.tdb
d.在openldap中,添加samba测试用户
[root@moban openldap]# cat /etc/passwd|grep admin(系统用户)
admin:x:500:500::/home/admin:/bin/bash
[root@moban samba]# cd /etc/openldap/
[root@moban openldap]# vi /etc/samba/smbusers
在最下面加入samba用户
admin sambatest #意思是说admin这个系统用户名有一个虚拟的SMB用户名:sambatest
[root@moban openldap]# vi sambauser.ldif
dn: uid=sambatest,ou=People,dc=etiantian,dc=org
objectClass: posixAccount
objectClass: top
objectClass: inetOrgPerson
objectClass: shadowAccount
gidNumber: 1009
givenName: sambatest
sn: sambatest
uid: sambatest
homeDirectory: /home/sambatest
loginShell: /bin/bash
shadowFlag: 0
shadowMin: 0
shadowMax: 99999
shadowWarning: 0
shadowInactive: 99999
shadowLastChange: 12011
shadowExpire: 99999
cn: sambatest
uidNumber: 24425
[root@moban openldap]# slapadd -l sambauser.ldif
58261bcf The first database does not allow slapadd; using the first available one (2)
_#################### 100.00% eta none elapsed none fast!
Closing DB...
e.设置操作系统从ldap中验证用户
提示:设置系统如果没有从/etc/passwd中找到用户就去openldap中验证。
[root@moban openldap]# authconfig-tui
User Information
[*] Use LDAP
Authentication
[*] Use Fingerprint reader
┌─────────┤ LDAP Settings ├───────
│
│ [ ] Use TLS
│ Server: ldap://192.168.0.111/
│ Base DN: dc=etiantian,dc=org
[root@moban openldap]# grep "ldap" /etc/nsswitch.conf
passwd: files ldap
shadow: files ldap
group: files ldap
netgroup: files ldap
automount: files ldap
[root@moban openldap]# tail -3 ldap.conf
URI ldap://192.168.0.111/
BASE dc=etiantian,dc=org
TLS_CACERTDIR /etc/openldap/cacerts
[root@moban openldap]# /etc/init.d/slapd start
[root@moban openldap]# /etc/init.d/smb start
f.测试从ldap中获取用户信息
[root@moban openldap]# id sambatest
uid=24425(sambatest) gid=1009 groups=1009
[root@moban openldap]# grep "sambatest" /etc/passwd
备注:从passwd文件中找不到sambatest,说明sambatest是从ldap中获取的。
g.设置测试用户sambatest密码
[root@moban openldap]# smbpasswd -a sambatest
New SMB password:123456789
Retype new SMB password:123456789
Added user sambatest.
h.测试samba中sambatest用户能否登录
[root@moban openldap]# smbclient -U sambatest //192.168.0.111/sambashare
Enter sambatest's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-36.el6_8]
smb: \> ls
. D 0 Sat Nov 5 20:38:28 2016
.. D 0 Thu Oct 27 13:01:13 2016
UM4SW7~D.LOG A 74 Thu Oct 27 19:29:01 2016
U41Y9B~1.LOG A 85 Thu Oct 27 19:37:24 2016
U0XZAY~G.LOG A 117 Thu Oct 27 19:18:40 2016
UAKC5V~4.LOG A 99 Thu Oct 27 19:27:02 2016
UO0D3H~P.LOG A 0 Sat Nov 5 20:38:28 2016
U3DW4T~X.LOG A 48 Thu Oct 27 19:30:14 2016
51760 blocks of size 524288. 45745 blocks available
smb: \>
[root@moban openldap]# smbclient -U sambatest //192.168.0.111/myshare
Enter sambatest's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-36.el6_8]
smb: \> ls
. D 0 Sat Nov 5 23:26:28 2016
.. DR 0 Fri Nov 11 22:26:21 2016
svndata D 0 Thu Oct 27 01:48:57 2016
新建 Microsoft Access 数据库.accdb A 512000 Sat Nov 5 23:26:28 2016
svnpasswd D 0 Sat Nov 5 21:02:06 2016
51760 blocks of size 524288. 45745 blocks available
smb: \>
通过以上结果可以看到samba通过openldap验证访问正常,再看看windows的访问,如下图:
Samba通过Openldap统一认证的更多相关文章
- kubernetes实战(十一):k8s使用openLDAP统一认证
1.基本概念 为了方便管理和集成jenkins,k8s.harbor.jenkins均使用openLDAP统一认证. 2.部署openLDAP 此处将openLDAP部署在k8s上,openLDAP可 ...
- LDAP+Gitea统一认证Git服务器账户管理openLdap和微软的ad
很多时候我们需要管理多个内容管理系统,比如Jira.Jenkins.GitEA/Gitlab等等各种管理系统,我们需要每一套管理系统每个人都管理一套密码,每套系统每套密码简直是一种灾难,于是LDAP可 ...
- Linux下LDAP统一认证解决方案
Linux下LDAP统一认证解决方案 --http://www.cangfengzhe.com/wangluoanquan/3.html 转自:http://www.cnblogs.com/MYSQL ...
- #研发解决方案介绍#IdCenter(内部统一认证系统)
郑昀 基于朱传志的设计文档 最后更新于2014/11/13 关键词:LDAP.认证.权限分配.IdCenter. 本文档适用人员:研发 曾经一个IT内部系统配一套帐号体系和授权 线上生产环境里 ...
- openvpn通过ldap或ad统一认证解决方案思路分享
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://oldboy.blog.51cto.com/2561410/986933 缘起:成 ...
- [原创]django+ldap+memcache实现单点登录+统一认证
前言 由于公司内部的系统越来越多,为了方便用户使用,通过django进行了单点登录和统一认证的尝试,目前实现了django项目的单点登录和非django项目的统一认证,中间波折挺多,涉及的技术包括dj ...
- [原创]django+ldap实现统一认证部分二(python-ldap实践)
前言 接上篇文章 [原创]django+ldap实现统一认证部分一(django-auth-ldap实践) 继续实现我们的统一认证 python-ldap 我在sso项目的backend/lib/co ...
- [原创]django+ldap实现统一认证部分一(django-auth-ldap实践)
前言 接之前我的文章,django+ldap+memcache实现单点登录+统一认证 ,ldap部署相关,ldap双机\LAM配置管理\ldap备份还原,目前来说,我们已经有了高可用性的ldap环境了 ...
- 云方案,依托H3C彩虹云存储架构,结合UIA统一认证系统,实现了用户数据的集中存储和管理
客户的声音 资料云项目在迷你云基础上二次开发,通过使用云存储技术及文件秒传技术,对文件进行统一存储与管理,以达到节约文件管理成本.存储成本目的:通过有效的文件版本控制机制,以达到风险管控的目的:通过多 ...
随机推荐
- 【C# Parallel】ParallelLoopState
总结 总之,要编写一个健壮的并行循环,必须在并行循环体中检测 ParallelLoopState 对象的 IsExceptional, IsStopped 和 LowestBreakIteration ...
- 【基础知识】CPU 是如何工作的 |CPU 通过总线读取内存的工作方式
一.简单cpu 是如何工作 方式讲解 CPU 的根本任务就是执行指令,对计算机来说最终都是一串由 0 和 1 组成的序列.CPU 从逻辑上可以划分成 3 个模块,分别是控制单元.运算单元和存储单元 ...
- 深入理解Cache工作原理
内容来源:https://zhuanlan.zhihu.com/p/435031232 内容来源:https://zhuanlan.zhihu.com/p/102293437 本文主要内容如下,基本涉 ...
- 解决gpg failed to sign the data fatal: failed to write commit object解决方案
今天有位新同事在comit代码的时候一直报这个错误: gpg failed to sign the data fatal: failed to write commit object. 看到网上说gp ...
- Oracle数据库的一些常用命令
转至:https://blog.csdn.net/qq_36843413/article/details/81409152?utm_medium=distribute.pc_relevant_t0.n ...
- spring 使用depends-on, lazy-init, defalut-lazy-init
depends-on 如果一个bean是另一个bean的依赖, 可以使用ref属性或者<ref/>标签来实现依赖 那么被依赖bean一定是要比依赖bean率先实例化, 而depends-o ...
- Html实现背景科技流星雨效果
<!doctype html><html><head><meta charset="utf-8" /><title>流星 ...
- ❀ Spring5学习大总结
一.了解 Spring 基本介绍.主要思想 IoC/DI 1.了解 Spring 基本介绍 (1) Spring是什么? Spring 是一个轻量级的 DI/IoC 和 AOP 容器的开源框架,致力于 ...
- HTTP请求过程和状态响应码
HTTP请求过程 我们在浏览器中输入一个URL,回车之后便可以在浏览器中观察到页面内容.实际上,这个过程是浏览器向网站所在的服务器发送了一个请求,网站服务器接收到这个请求后进行处理和解析,然后返回对应 ...
- c语言刷 链表题记录
61. 旋转链表 /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode * ...