This guide will show you how you can integrate aCentOS 7Server with no Graphical User Interfaceto[Samba4 Active Directory Domain Controller][3]from command line using Authconfig software.
This type of setup provides a single centralized account database held bySamba and allows the AD users to authenticate to CentOS server across the network infrastructure.
#### Requirements
1. [Create an Active Directory Infrastructure with Samba4 on Ubuntu][1]
2. [CentOS 7.3 Installation Guide][2]
### Step 1: Configure CentOS for Samba4 AD DC
1.Before starting to joinCentOS 7Server into aSamba4 DCyou need to assure that the network interface is properly configured to query domain via DNS service.
Run[ip address][4]command to list your machine network interfaces and choose the specific NIC to edit by issuingnmtui-editcommand against the interface name, such asens33in this example, as illustrated below.
2.Once the network interface is opened for editing, add the static IPv4 configurations best suited for your LAN and make sure you setup Samba AD Domain Controllers IP addresses for the DNS servers.
Also, append the name of your domain in search domains filed and navigate toOKbutton using[TAB]key to apply changes.
The search domains filed assures that the domain counterpart is automatically appended by DNS resolution (FQDN) when you use only a short name for a domain DNS record.
3.Finally, restart the network daemon to apply changes and test if DNS resolution is properly configured by issuing series ofpingcommands against the domain name and domain controllers short names as shown below.
```
# systemctl restart network.service
# ping -c2 tecmint.lan
# ping -c2 adc1
# ping -c2 adc2
```
[![Verify DNS Resolution on Domain](https://www.tecmint.com/wp-content/uploads/2017/07/Verify-DNS-Resolution-on-Domain.png)][7]
Verify DNS Resolution on Domain
4.Also, configure your machinehostname and reboot the machine to properly apply the settings by issuing the following commands.
```
# hostnamectl set-hostname your_hostname
# init 6
```
Verify if hostname was correctly applied with the below commands.
```
# cat /etc/hostname
# hostname
```
5.Finally, sync local time with Samba4 AD DC by issuing the below commands with root privileges.
```
# yum install ntpdate
# ntpdate domain.tld
```
[![Sync Time with Samba4 AD DC](https://www.tecmint.com/wp-content/uploads/2017/07/Sync-Time-with-Samba4-AD-DC.png)][8]
Sync Time with Samba4 AD DC
### Step 2: Join CentOS 7 Server to Samba4 AD DC
6.To join CentOS 7 server to Samba4 Active Directory, first install the following packages on your machine from an account with root privileges.
7.In order to integrate CentOS 7 server to a domain controller runauthconfig-tuigraphical utility with root privileges and use the below configurations as described below.
```
# authconfig-tui
```
At the first prompt screen choose:
* OnUser Information:
* Use Winbind
* OnAuthenticationtab select by pressing[Space]key:
9.To perform domain joining navigate toJoin Domainbutton using[tab]key and hit[Enter]key to join domain.
At the next screen prompt, add the credentials for aSamba4 ADaccount with elevated privileges to perform the machine account joining into AD and hitOKto apply settings and close the prompt.
Be aware that when you type the user password, the credentials won’t be shown in the password screen. On the remaining screen hitOKagain to finish domain integration for CentOS 7 machine.
[![Join Domain to Samba4 AD DC](https://www.tecmint.com/wp-content/uploads/2017/07/Join-Domain-to-Samba4-AD-DC.png)][11]
To force adding a machine into a specificSamba AD Organizational Unit, get your machine exact name using hostname command and create a new Computer object in that OU with the name of your machine.
The best way to add a new object into a Samba4 AD is by usingADUCtool from a Windows machine integrated into the domain with[RSAT tools installed][13]on it.
Important: An alternate method of joining a domain is by usingauthconfigcommand line which offers extensive control over the integration process.
However, this method is prone to errors do to its numerous parameters as illustrated on the below command excerpt. The command must be typed into a single long line.
10.After the machine has been joined to domain, verify if winbind service is up and running by issuing the below command.
```
# systemctl status winbind.service
```
11.Then, check if CentOS machine object has been successfully created in Samba4 AD. Use AD Users and Computerstool from a Windows machine with RSAT tools installed and navigate to your domain Computers container. A new AD computer account object with name of your CentOS 7 server should be listed in the right plane.
12.Finally, tweak the configuration by opening samba main configuration file (/etc/samba/smb.conf) with a text editor and append the below lines at the end of the[global]configuration block as illustrated below:
13.In order to create local homes on the machine for AD accounts at their first logon run the below command.
```
# authconfig --enablemkhomedir --update
```
14.Finally, restart Samba daemon to reflect changes and verify domain joining by performing a logon on the server with an AD account. The home directory for the AD account should be automatically created.
### Step 3: Login to CentOS with a Samba4 AD DC Account
18.To authenticate with a domain user in CentOS, use one of the following command line syntaxes.
```
# su - ‘domain\domain_user’
# su - domain\\domain_user
```
Or use the below syntax in case winbind use default domain = true parameter is set to samba configuration file.
```
# su - domain_user
# su - domain_user@domain.tld
```
19.In order to add root privileges for a domain user or group, editsudoersfile usingvisudocommand and add the following lines as illustrated on the below screenshot.
```
YOUR_DOMAIN\\domain_username ALL=(ALL:ALL) ALL #For domain users
%YOUR_DOMAIN\\your_domain\ group ALL=(ALL:ALL) ALL #For domain groups
```
Or use the below excerpt in case winbind use default domain = true parameter is set to samba configuration file.
```
domain_username ALL=(ALL:ALL) ALL #For domain users
%your_domain\ group ALL=(ALL:ALL) ALL #For domain groups
```
[![Grant Root Privileges on Domain Users](https://www.tecmint.com/wp-content/uploads/2017/07/Grant-Root-Privileges-on-Domain-Users.jpg)][19]
Grant Root Privileges on Domain Users
20.The following series of commands against a Samba4 AD DC can also be useful for troubleshooting purposes:
```
# wbinfo -p #Ping domain
# wbinfo -n domain_account #Get the SID of a domain account
# wbinfo -t #Check trust relationship
```
21.To leave the domain run the following command against your domain name using a domain account with elevated privileges. After the machine account has been removed from the AD, reboot the machine to revert changes before the integration process.
```
# net ads leave -w DOMAIN -U domain_admin
# init 6
```
That’s all! Although this procedure is mainly focused on joining aCentOS 7server to a Samba4 AD DC, the same steps described here are also valid for integrating a CentOS server into a Microsoft Windows Server 2012 Active Directory.
I'am a computer addicted guy, a fan of open source and linux based system software, have about 4 years experience with Linux distributions desktop, servers and bash scripting.