企业中若是使用了 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
[root@host01 ~]# yum install realmd oddjob oddjob-mkhomedir sssd adcli openldap-clients policycoreutils-python samba-common samba-common-tools krb5-workstation
[root@host01 ~]# timedatectl set-timezone Asia/Shanghai
[root@host01 ~]# hostnamectl set-hostname host01.test.local [root@host01 ~]# vim /etc/resolv.conf nameserver 192.168.127.128 # 域控制器的ip地址
[root@host01 ~]# realm join test.local Administrator 的密码:
[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
[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