Redhat Enterprise Linux 6 update 3 (RHEL 6.3) 与WINDOWS SERVER 2008 Active Directory 集成

好久没用Windows,这周在做hadoop的安全认证相关事情,打算hadoop改用kerberos进行用户认证。kerberos的实现在linux下有很多方案了,因为微软的Active Directory在企业中应用还是比较广泛的,就打算装个windows server 做域控制器,来提供LDAP 目录检索和kerberos认证服务。想想对AD还是挺熟悉的,若干年前就搞过了,于是兴致满满的开工了。

周一装好了windows server 2003 ,这就是悲催故事的开始。。。。。配好了AD和DNS,然后有点悲催,折腾了两天具体就不谈了,回头想是AD中的属性名称与linux不同,然后又按照win2008的属性名做映射,能通才怪了。虽然最后没配通,但是对整个AD与linux的相关集成有了更深入了解。

文中用到的一些信息如下:

域控制器 BIDC.BI.HYLANDTEC.COM

域 :BI.HYLANDTEC.COM

用户检索ldap的bind用户名称 :binduser

1.WINDOWS 配置部分

在windows 2008上装完AD以后注意要装上NIS扩展模型,属性中就会出现一个新的Tab页(Unix Attributes) 。设置好uid,gid,homedirectory等AD中的用户和组才能为linux所用。

装完NIS以后新增一个group

而后设置linuxgrp的gid

而后新建用户binduser

设置好用户的unix相关属性

设置完以后用系统自带的ADSI EDIT (ADSIEDIT.MSC) 或者Mark Russinovich 的Active Directory Explorer或者ldapsearch等等来看看用户属性。下图是Active Directory Explorer的截图,如果需要完成属性最好还是用adsiedit来看:

Linux中用户所必需的loginshell,uid,gid等等已经出现了。AD中的配置肩搭到这边即可用了,剩下主要是linux下的工作。

2.linux配置部分

Linux 下有很多方案,用Winbind,sssd.nslcd 的,其中nslcd是rhel 6中引入的,所以本次在rhel6.3中就采用nslcd的方式。

 

yum install pam_krb5 pam_ldap nss-pam-ldapd nscd openldap-clients

装完以后先执行以下命令试试能否和AD服务器连通,如果服务器不通,检查防火墙和网络设置。

 ldapsearch -x -LLL -H ‘ldap://bidc.bi.hylandtec.com’ -b ‘DC=BI,DC=HYLANDTEC,DC=COM’ -E pr=200/noprompt -D “[email protected]” -W -s sub “(cn=binduser)”

应该会出来类似的结果,注意unix相关属性应该顺利被读取。

与ldap服务器连接无问题后以root用户运行

 authconfig-tui

按照如下配置认证方式:

配置LDAP

配置kerberos

按OK保存以后会提示nslcd服务启动:

检查Name Service Switch 已经配置为使用ldap了。/etc/nsswitch.conf 文件中以下三行是否有ldap。

passwd:     files ldap

shadow:     files ldap

group:      files ldap

由于AD不允许匿名使用目录服务,以及需要对AD中的属性映射到unix下的属性。还需要对nslcd做手工配置。

修改/etc/nslcd.conf 文件 (注:windows server 2003 装SFU 的NIS 以后的ladp的属性名称和2008的不一样,配置文件中的需要写较多的map 但其实也是可以用的)

binddn CN=binduser,CN=Users,DC=BI,DC=HYLANDTEC,DC=COM

bindpw bind..321

# Mappings for Active Directory

pagesize 1000

referrals off filter

passwd (&(objectClass=user)(!(objectClass=computer))(uidNumber=*)(unixHomeDirectory=*))

map    passwd uid              sAMAccountName

map    passwd homeDirectory    unixHomeDirectory

map    passwd gecos            displayName

filter shadow (&(objectClass=user)(!(objectClass=computer))(uidNumber=*)(unixHomeDirectory=*))

map    shadow uid              sAMAccountName

map    shadow shadowLastChange pwdLastSet

filter group  (objectClass=group)

map    group  uniqueMember     member

修改完后执行/etc/init.d/nslcd restart 重启nslcd

重启完毕后执行getent passwd ,

nscd:x:28:28:NSCD Daemon:/:/sbin/nologin

nslcd:x:65:55:LDAP Client User:/:/sbin/nologin

binduser:*:10000:10000:binduser:/home/binduser:/bin/sh

出现AD中的用户,如binduser就说明nslcd配置正确。

因为LDAP过来的用户并没有创建主目录,所以需要自动新建主目录。在/etc/pam.d/sshd 以及/etc/pam.d/logon中增加一行

session required pam_mkhomedir.so skel=/etc/skel umask=0022

kerberos要求各台服务器间时间同步,误差不能大于十分钟,所以与域控制器做好时间同步。

ntpdate bidc.bi.hylandtec.com

最后检查主机名是否设置正确/etc/hosts

172.16.130.227 rhel227.bi.hylandtec.com rhel227

执行hostname命令设置主机名 ,并检查/etc/sysconfig/network 文件中的主机名是否正确设置。

hostname rhel227.bi.hylandtec.com

 

编辑, /etc/krb5.conf在libdefaults部分 增加default_tgs_enctypes,default_tkt_enctypes,permitted_enctypes 三个属性,例如:

[libdefaults]

default_realm = BI.HYLANDTEC.COM

dns_lookup_realm = false

dns_lookup_kdc = false

ticket_lifetime = 24h

renew_lifetime = 7d

forwardable = true

default_tgs_enctypes = rc4-hmac

default_tkt_enctypes = rc4-hmac

permitted_enctypes = rc4-hmac

编辑/etc/samba/smb.conf ,内容如下,workgroup写域的第一部分:

workgroup = BI

server string = Samba Server Version %v

netbios name = RHEL227

security = ads

realm = BI.HYLANDTEC.COM

dedicated keytab file = / etc/krb5.keytab

kerberos method = system keytab

password server = BIDC.BI.HYLANDTEC.COM

使用域管理员用户将计算机加入域

[root@rhel227 ~]# net ads join OSNAME=RHEL OSVer=6 -U Administrator

Enter Administrator’s password:

Using short domain name — BI

Joined ‘RHEL227’ to realm ‘BI.HYLANDTEC.COM’

查看keytab ,顺利出现主机内容就表示配置成功。

[root@rhel227 security]# klist -ke

Keytab name: WRFILE:/etc/krb5.keytab

KVNO Principal —- ————————————————————————–

3 host/[email protected] (des-cbc-crc)

3 host/[email protected] (des-cbc-md5)

3 host/[email protected] (arcfour-hmac)

3 host/[email protected] (des-cbc-crc)

3 host/[email protected] (des-cbc-md5)

3 host/[email protected] (arcfour-hmac)

3 [email protected] (des-cbc-crc)

3 [email protected] (des-cbc-md5)

3 [email protected] (arcfour-hmac)

 

而后我们就可以尝试使用AD上的用户登录linux主机了。。

[root@rhel232 ~]# ssh [email protected]

[email protected]’s password:

Creating directory ‘/home/binduser’.

-sh-4.1$ hostname

rhel227.bi.hylandtec.com

-sh-4.1$ id binduser

uid=10000(binduser) gid=10000(linuxgrp) groups=10000(linuxgrp)

顺利登录,大功告成。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据