温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。
Fayson的github:https://github.com/fayson/cdhproject
提示:代码块部分可以左右滑动查看噢
1.文档编写目的
在前面的文章Fayson讲了《1.如何在RedHat7上安装OpenLDA并配置客户端》、《2.如何在RedHat7中实现OpenLDAP集成SSH登录并使用sssd同步用户》、《3.如何RedHat7上实现OpenLDAP的主主同步》、《4.如何为Hive集成RedHat7的OpenLDAP认证》、《5.如何为Impala集成Redhat7的OpenLDAP认证》以及《6.如何为Hue集成RedHat7的OpenLDAP认证》。本篇文章主要介绍如何在RedHat7的OpenLDAP中将一个用户添加到多个组中。
1.测试环境描述
2.添加测试用户及用户组
3.验证用户组
1.RedHat7.3
2.OpenLDAP版本2.4.44
1.OpenLDAP已安装且正常使用
2.测试环境描述
IP地址 | HOSTNAME | 描述 |
---|---|---|
172.31.24.169 | ip-172-31-24-169.ap-southeast-1.compute.internal | OpenLDAP已安装 |
172.31.16.68 | ip-172-31-16-68.ap-southeast-1.compute.internal | OpenLDAP已安装 |
这里我们将172.31.24.169做为OpenLDAP的主节点,172.31.16.68做为OpenLDAP的备节点,具体RedHat7下OpenLDAP的HA实现可以参考《3.如何RedHat7上实现OpenLDAP的主主同步》
3.修改sssd.conf配置文件
修改/ect/sssd/sssd.conf配置文件,内容如下:
[root@ip-172-31-24-169 ldap]# vim /etc/sssd/sssd.conf
[domain/default]
autofs_provider = ldap
#ldap_schema = rfc2307bis
#ldap_group_member = uniqueMember
krb5_realm = FAYSON.COM
ldap_search_base = dc=fayson,dc=com
krb5_server = ip-172-31-16-68.ap-southeast-1.compute.internal
id_provider = ldap
auth_provider = ldap
chpass_provider = ldap
ldap_uri = ldap://ip-172-31-24-169.ap-southeast-1.compute.internal
ldap_id_use_start_tls = True
ldap_tls_reqcert = allow
cache_credentials = True
ldap_tls_cacertdir = /etc/openldap/cacerts
[sssd]
services = nss, pam, autofs
domains = default
[nss]
homedir_substring = /home
[pam]
[sudo]
[autofs]
[ssh]
[pac]
[ifp]
[secrets]
(可左右滑动)
在前面Fayson安装SSSD服务是执行authconfig命令中指定了--enablerfc2307bis属性,所以在sssd.conf文件中会有该配置项。
LDAP的Schema定义了服务器上检索到默认属性名以及一些属性的含义,特别是成员属性。有两种最广泛的使用模式rfc2307和rfc2307bis,rfc2307为默认的模式。当使用rfc2307模式时,组成员是配置在memberUid的属性中。使用rfc2307bis模式时,需要在sssd.conf文件中增加如下配置;
ldap_schema = rfc2307bis
ldap_group_member = uniqueMember
(可左右滑动)
注意:这里Fayson未测试通,大家有测通的可以告诉Fayson,谢谢!!!
4.添加测试用户及用户组
这里我们添加一个测试用户faysontest2,将faysontest2用户添加到faysontest2和faysontest3组中。
1.编辑user_faysontest2.ldif文件,内容如下:
[root@ip-172-31-24-169 ldap]# vim user_faysontest2.ldif
dn: uid=faysontest2,ou=People,dc=fayson,dc=com
uid: faysontest2
cn: faysontest2
objectClass: account
objectClass: posixAccount
objectClass: top
objectClass: shadowAccount
userPassword: {SSHA}KYgsfyI/uny0dKPNeMRNG54BdwV6KlWA
shadowLastChange: 17493
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 1999
gidNumber: 1999
homeDirectory: /home/faysontest2
(可左右滑动)
用户的ldif文件中包含了用户默认的用户组faysontest2,在文件中我们使用gidNumber来添加faysontest2的用户组。
2.编辑group_faysontest2.ldif文件,内容如下:
[root@ip-172-31-24-169 ldap]# vim group_faysontest2.ldif
dn: cn=faysontest2,ou=Group,dc=fayson,dc=com
objectClass: posixGroup
objectClass: top
cn: faysontest2
userPassword: {SSHA}KYgsfyI/uny0dKPNeMRNG54BdwV6KlWA
gidNumber: 1999
dn: cn=faysontest3,ou=Group,dc=fayson,dc=com
objectClass: posixGroup
objectClass: top
cn: faysontest3
userPassword: {SSHA}KYgsfyI/uny0dKPNeMRNG54BdwV6KlWA
gidNumber: 1997
memberUid: faysontest2
(可左右滑动)
在组的ldif文件中,我们在faysontest3组条目下增加了memberUid: faysontest2来添加组和用户的依赖关系。
3.在命令行执行如下命令,将用户和用户组导入OpenLDAP
ldapadd -D "cn=Manager,dc=fayson,dc=com" -W -x -f group_faysontest2.ldif
ldapadd -D "cn=Manager,dc=fayson,dc=com" -W -x -f user_faysontest2.ldif
(可左右滑动)
4.查看用户faysontest2的用户组
[root@ip-172-31-24-169 ~]# id faysontest2
uid=1999(faysontest2) gid=1999(faysontest2) groups=1999(faysontest2),1997(faysontest3)
[root@ip-172-31-24-169 ~]#
(可左右滑动)
这里我们可以看到faysontest2用户包含了两个组faysontest2和faysontest3
5.将用户添加到已有的组
在用户和用户组已经存在的情况下可以通过ldapmodify命令修改修改条目信息将用户添加到已有的用户组中,下面我们通过示例来说明如何将用户faysontest用户添加到已有的faysontest3组中。
1.查看faysontest现有的用户组
[root@ip-172-31-24-169 ldap]# id faysontest
uid=10099(faysontest) gid=10099(faysontest) groups=10099(faysontest)
[root@ip-172-31-24-169 ldap]#
(可左右滑动)
2.编辑update_group_faysontest3.ldif文件,内容如下:
[root@ip-172-31-24-169 ldap]# vim update_group_faysontest3.ldif
dn: cn=faysontest3,ou=Group,dc=fayson,dc=com
changetype: modify
add: memberUid
memberUid: faysontest
(可左右滑动)
如上内容描述向faysontest3用户组中添加faysontest用户
3.使用如下命令导入修改的ldif文件
ldapmodify -x -D "cn=Manager,dc=fayson,dc=com" -W -f update_group_faysontest3.ldif
(可左右滑动)
4.查看faysontest用户是否在faysontest3组中
[root@ip-172-31-24-169 ldap]# rm -rf /var/lib/sss/db/cache_default.ldb
[root@ip-172-31-24-169 ldap]# systemctl restart sssd
[root@ip-172-31-24-169 ldap]# id faysontest
uid=10099(faysontest) gid=10099(faysontest) groups=10099(faysontest),1997(faysontest3)
[root@ip-172-31-24-169 ldap]#
(可左右滑动)
这里我们看到将faysontest用户添加到了faysontest3用户组中。
6.总结
更多openldap资料参考:
http://www.tldp.org/HOWTO/LDAP-HOWTO/utilities.html
http://www.openldap.org/doc/admin24/OpenLDAP-Admin-Guide.pdf
https://www.oav.net/mirrors/ldapv3.pdf
https://linux.cn/article-8853-1.html
https://docs.kanboard.org/en/latest/admin_guide/ldap_examples.html
提示:代码块部分可以左右滑动查看噢
为天地立心,为生民立命,为往圣继绝学,为万世开太平。 温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。
推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有