CentOS 7 加入 AD 域

前言

企業中若是使用了 Linux 和 Windows,想要統一管理,則能夠將須要管理的 Linux 主機和 Windows 主機都加 入Windows Active Directory,即 AD 也就是咱們常說的域。如下即是記錄 CentOS7 加入 AD 域的操做,使用的是 Realmd,它配置 Linux 系統服務(如 sssd 或 winbind)來執行實際的網絡身份驗證和用戶賬戶查找。python

環境信息

域:test.local
域控:dc01.test.local(IP:192.168.127.128)
域控系統:Windows Server 2016
加域系統:CentOS 7.6linux

因 Windows Server 配置爲域控比較簡單,網上資料較多,這方面可自行網上查詢。另外 CentOS 主機在作加域測試前請關掉 firewalld 服務和 selinux。shell

安裝配置

  1. 在 Windows AD 域環境準備好後,登錄要加入域的 CentOS 系統,安裝加域須要的安裝包。
    [root@host01 ~]# yum install realmd oddjob oddjob-mkhomedir sssd adcli openldap-clients policycoreutils-python samba-common samba-common-tools krb5-workstation
  2. 使用 timedatectl 命令查看 linux 主機時區是否正常,若是不正常請使用如下命令修改時區:
    [root@host01 ~]# timedatectl set-timezone Asia/Shanghai
  3. 設置須要加域的 CentOS 主機名稱,而後配置 dns server 指向域控。
    [root@host01 ~]# hostnamectl  set-hostname   host01.test.local
    [root@host01 ~]# vim /etc/resolv.conf
    nameserver 192.168.127.128   # 域控制器的ip地址
  4. 設置將 CentOS 加域。
    [root@host01 ~]# realm join test.local
    Administrator 的密碼:
  5. 確認 /etc/sssd/sssd.conf 配置信息以下。
    [root@host01 ~]# cat /etc/sssd/sssd.conf
    [sssd]
    domains = test.local
    config_file_version = 2
    services = nss, pam
    [domain/test.local]
    ad_server = test.local
    ad_domain = test.local
    krb5_realm = TEST.LOCAL
    realmd_tags = manages-system joined-with-adcli 
    cache_credentials = True
    id_provider = ad
    krb5_store_password_if_offline = True
    default_shell = /bin/bash
    ldap_id_mapping = True
    use_fully_qualified_names = True
    fallback_homedir = /home/%u@%d
    access_provider = ad
  6. 啓用 sssd 驗證。
    [root@host01 ~]# authconfig --enablesssd --enablesssdauth --enablemkhomedir --update
    [root@host01 ~]# systemctl start sssd

驗證加域

[root@host01 ~]# id zhangsan@test.local
uid=347401103(zhangsan@test.local) gid=347400513(domain users@test.local) groups=347400513(domain users@test.local)

若是每次驗證帳戶不想要加域名後綴,可編輯配置文件 /etc/sssd/sssd.conf:
修改如下兩個參數:vim

use_fully_qualified_names = True
fallback_homedir = /home/%u@%d
改成:
use_fully_qualified_names = True
fallback_homedir = /home/%u@%dcentos

而後重啓 sssd 服務:bash

[root@host01 ~]# systemctl restart sssd

再次驗證,便可不須要加後綴域名:網絡

[root@host01 ~]# id  zhangsan
uid=347401103(zhangsan) gid=347400513(domain users) groups=347400513(domain users)

此時即可以使用域帳戶登陸剛纔已經加入域的 CentOS 系統。app

參考:https://www.thegeekdiary.com/how-to-connect-to-an-active-directory-domain-using-realmd-configure-centos-rhel-7-as-active-directory-client/less

相關文章
相關標籤/搜索