Centos7/Active Directory authentication using nss-pam-ldapd,

來源:互聯網
上載者:User

Centos7/Active Directory authentication using nss-pam-ldapd,

Centos使用AD賬戶進行驗證,網上查有很多種,包括samba+winbind,sssd,nss-pam-ldapd等多種方式。今天介紹通過nss-pam-ldap驗證AD帳號。

一.實驗環境:

兩台主機:一台windows server2012 R2 域控,一台centos7.2用戶端使用AD帳號驗證

1.windows os:Active Directory 2012 R2 

IP:10.10.1.1

hostname: ad

Domain ghost.com

2.linux os: centos 7.2 1511

IP:10.10.1.10

hostname:server1.ghost.com

二.實驗步驟:

AD域控:

hostname:ad

IP:10.10.1.1

1.Create AD and DNS Server:Server Manager---->Add roles and features---->Active Directory Domain Services+DNS Server 在此不詳細敘述具體步驟(大家都懂的^_^)

2.因為windows 2012 R2沒有Identity Management for UNIX Component需要啟用該組件,windows2016就不需要安裝此組件。命令如下:

Dism.exe /online /enable-feature /featurename:adminui 

Dism.exe /online /enable-feature /featurename:nis

Dism.exe /online /enable-feature /featurename:psync

同時可以參照以下連結:

https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc731178(v=ws.11)

啟用此組件後,帳號屬性中會增加UNIX Attributes下拉框,在AD users and Computers 視圖中啟用進階功能會看到Attribute Editor.

 

3. 關閉windows防火牆,在DNS添加server1的A紀錄:10.10.1.10解析網域名稱。

4.建立OU GHOST和使用者zhangsan,linux_ad用於驗證,如果linux_ad提示驗證有問題可以嘗試用administrator帳號試試,如。

四.上面有點囉嗦啦!接下來說的是大家感興趣的事情,linux的相關設定。

1.系統安裝完畢,關閉selinux,firewalld.

2.設定IP和DNS

[root@server1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.10.1.10
NETMASK=255.255.0.0
DNS=10.10.1.1
[root@server1 ~]# cat /etc/resolv.conf
search localdomain ghost.com
nameserver 10.10.1.1
[root@server1 ~]#yum -y install nss-pam-ldapd openldap-clients telnet
通過nss-pam-ldapd驗證需要配置以下幾個檔案,其中system-auth-ac和password-auth-ac修改是一樣的。

[root@server1 ~]# cat /etc/nslcd.conf

uid nslcd
gid ldap
uri ldap://ad.ghost.com:389 #
base ou=GHOST,dc=ghost,dc=com #OU, DC一定要對應。
binddn cn=linux_ad,cn=users,dc=ghost,dc=com #cn,dn的資訊可以通過AD中帳號Aittribute Editor中distinguishedName的值進行查看。
bindpw linux_ad
scope group sub
scope hosts sub
bind_timelimit 3
timelimit 3
pagesize 1000
referrals off
filter passwd (&(objectClass=user)(!(objectClass=computer))(unixHomeDirectory=*))
map    passwd homeDirectory    unixHomeDirectory
filter shadow (&(objectClass=user)(!(objectClass=computer))(unixHomeDirectory=*))
map    shadow shadowLastChange pwdLastSet
filter group  (objectClass=group)
scope sub
ssl off
tls_reqcert never

 

[root@server1 ~]# cat /etc/nsswitch.conf
passwd:     files  ldap #添加ldap驗證方式
shadow:     files  ldap
group:      files  ldap
hosts:      files dns
bootparams: nisplus [NOTFOUND=return] files
ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files ldap
netgroup:   files  ldap
publickey:  nisplus
automount:  files ldap
aliases:    files nisplus

 

[root@server1 ~]# cat /etc/pam.d/system-auth-ac
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 1000 quiet_success
auth        sufficient    pam_ldap.so use_first_pass #添加ldap驗證方式
auth        required      pam_deny.so

account     required      pam_unix.so broken_shadow
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     [default=bad success=ok user_unknown=ignore] pam_ldap.so #添加ldap驗證方式
account     required      pam_permit.so

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password    sufficient    pam_ldap.so use_authtok #添加ldap驗證方式
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
-session     optional      pam_systemd.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
session     optional      pam_ldap.so #添加ldap驗證方式

 

測試AD 389連接埠是否正常 

[root@server1 ~]# telnet 10.10.1.1 389
Trying 10.10.1.1...
Connected to 10.10.1.1.
Escape character is '^]'.
 

啟動nslcd服務

[root@server1 ~]# systemctl start nslcd
[root@server1 ~]# systemctl status nslcd
● nslcd.service - Naming services LDAP client daemon.
   Loaded: loaded (/usr/lib/systemd/system/nslcd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-02-07 16:29:57 CST; 13s ago
  Process: 6904 ExecStart=/usr/sbin/nslcd (code=exited, status=0/SUCCESS)
 Main PID: 6905 (nslcd)
   CGroup: /system.slice/nslcd.service
           └─6905 /usr/sbin/nslcd

Feb 07 16:29:57 server1.ghost.com systemd[1]: Starting Naming services LDAP client daemon....
Feb 07 16:29:57 server1.ghost.com systemd[1]: PID file /var/run/nslcd/nslcd.pid not readable (yet?) after start.
Feb 07 16:29:57 server1.ghost.com nslcd[6905]: version 0.8.13 starting
Feb 07 16:29:57 server1.ghost.com nslcd[6905]: accepting connections
Feb 07 16:29:57 server1.ghost.com systemd[1]: Started Naming services LDAP client daemon..
Feb 07 16:30:06 server1.ghost.com systemd[1]: Started Naming services LDAP client daemon.. 

 

使用ldapsearch命令測試是否驗證成功。

ldapsearch -h ad.ghost.com -b dc=ghost,dc=com -D cn=linux_ad,cn=users,dc=ghost,dc=com -W -p 389

 

查看linux系統中是否存在zhangsan

[root@server1 ~]# id zhangsan

uid=10001(zhangsan) gid=10000 groups=10000

到此Centos 通過AD帳號驗證已經成功啦!!!

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.