系统相关
首页 > 系统相关> > CentOS 7 加入 AD 域

CentOS 7 加入 AD 域

作者:互联网

前言

企业中如果使用了 Linux 和 Windows,想要统一管理,则可以将需要管理的 Linux 主机和 Windows 主机都加 入Windows Active Directory,即 AD 也就是我们常说的域。以下便是记录 CentOS7 加入 AD 域的操作,使用的是 Realmd,它配置 Linux 系统服务(如 sssd 或 winbind)来执行实际的网络身份验证和用户帐户查找。

环境信息

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

因 Windows Server 配置为域控比较简单,网上资料较多,这方面可自行网上查询。另外 CentOS 主机在做加域测试前请关掉 firewalld 服务和 selinux。

安装配置

  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:
修改以下两个参数:

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

然后重启 sssd 服务:

[root@host01 ~]# systemctl restart sssd

再次验证,即可不需要加后缀域名:

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

此时便可以使用域账户登录刚才已经加入域的 CentOS 系统。

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

标签:host01,AD,CentOS,sssd,root,加入,test,local
来源: https://blog.51cto.com/liubin0505star/2668504