Join SQL Server on a Linux host to an Active Directory domain

APPLIES TO: yesSQL Server (Linux only) noAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

This article provides general guidance on how to join a SQL Server Linux host machine to an Active Directory (AD) domain. There are two methods: use a built-in SSSD package or use third-party Active Directory providers. Examples of third-party domain join products are PowerBroker Identity Services (PBIS), One Identity, and Centrify. This guide includes steps to check your Active Directory configuration. However, it is not intended to provide instructions on how to join a machine to a domain when using third-party utilities.

Prerequisites

Before you configure Active Directory authentication, you need to set up an Active Directory domain controller, Windows, on your network. Then join your SQL Server on Linux host to an Active Directory domain.

Important

The sample steps described in this article are for guidance only. Actual steps may slightly differ in your environment depending on how your overall environment is configured. Engage your system and domain administrators for your environment for specific configuration, customization, and any required troubleshooting.

Check the connection to a domain controller

Check that you can contact the domain controller with both the short and fully qualified names of the domain:

ping contoso
ping contoso.com

Tip

This tutorial uses contoso.com and CONTOSO.COM as example domain and realm names, respectively. It also uses DC1.CONTOSO.COM as the example fully qualified domain name of the domain controller. You must replace these names with your own values.

If either of these name checks fail, update your domain search list. The following sections provide instructions for Ubuntu, Red Hat Enterprise Linux (RHEL), and SUSE Linux Enterprise Server (SLES) respectively.

Ubuntu

  1. Edit the /etc/network/interfaces file, so that your Active Directory domain is in the domain search list:

    # The primary network interface
    auto eth0
    iface eth0 inet dhcp
    dns-nameservers **<AD domain controller IP address>**
    dns-search **<AD domain name>**
    

    Note

    The network interface, eth0, might differ for different machines. To find out which one you're using, run ifconfig. Then copy the interface that has an IP address and transmitted and received bytes.

  2. After editing this file, restart the network service:

    sudo ifdown eth0 && sudo ifup eth0
    
  3. Next, check that your /etc/resolv.conf file contains a line like the following example:

    search contoso.com com  
    nameserver **<AD domain controller IP address>**
    

RHEL

  1. Edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file, so that your Active Directory domain is in the domain search list. Or edit another interface config file as appropriate:

    PEERDNS=no
    DNS1=**<AD domain controller IP address>**
    DOMAIN="contoso.com com"
    
  2. After editing this file, restart the network service:

    sudo systemctl restart network
    
  3. Now check that your /etc/resolv.conf file contains a line like the following example:

    search contoso.com com  
    nameserver **<AD domain controller IP address>**
    
  4. If you still cannot ping the domain controller, find the fully qualified domain name and IP address of the domain controller. An example domain name is DC1.CONTOSO.COM. Add the following entry to /etc/hosts:

    **<IP address>** DC1.CONTOSO.COM CONTOSO.COM CONTOSO
    

SLES

  1. Edit the /etc/sysconfig/network/config file, so that your Active Directory domain controller IP is used for DNS queries and your Active Directory domain is in the domain search list:

    NETCONFIG_DNS_STATIC_SEARCHLIST=""
    NETCONFIG_DNS_STATIC_SERVERS="**<AD domain controller IP address>**"
    
  2. After editing this file, restart the network service:

    sudo systemctl restart network
    
  3. Next, check that your /etc/resolv.conf file contains a line like the following example:

    search contoso.com com
    nameserver **<AD domain controller IP address>**
    

Join to the AD domain

After the basic configuration and connectivity with domain controller is verified, there are two options for joining a SQL Server Linux host machine with Active Directory domain controller:

Option 1: Use SSSD package to join AD domain

This method joins the SQL Server host to an AD domain using realmd and sssd packages.

Note

This is the preferred method of joining a Linux host to an AD domain controller.

Use the following steps to join a SQL Server host to an Active Directory domain:

  1. Use realmd to join your host machine to your AD Domain. You must first install both the realmd and Kerberos client packages on the SQL Server host machine using your Linux distribution's package manager:

    RHEL:

    sudo yum install realmd krb5-workstation
    

    SUSE:

    sudo zypper install realmd krb5-client
    

    Ubuntu:

    sudo apt-get install realmd krb5-user software-properties-common python-software-properties packagekit
    
  2. If the Kerberos client package installation prompts you for a realm name, enter your domain name in uppercase.

  3. After you confirm that your DNS is configured properly, join the domain by running the following command. You must authenticate using an AD account that has sufficient privileges in AD to join a new machine to the domain. This command creates a new computer account in AD, creates the /etc/krb5.keytab host keytab file, configures the domain in /etc/sssd/sssd.conf, and updates /etc/krb5.conf.

    sudo realm join contoso.com -U 'user@CONTOSO.COM' -v
    

    You should see the message, Successfully enrolled machine in realm.

    The following table lists some error messages that you could receive and suggestions on resolving them:

    Error message Recommendation
    Necessary packages are not installed Install those packages using your Linux distribution's package manager before running the realm join command again.
    Insufficient permissions to join the domain Check with a domain administrator that you have sufficient permissions to join Linux machines to your domain.
    KDC reply did not match expectations You may not have specified the correct realm name for the user. Realm names are case-sensitive, usually uppercase, and can be identified with the command realm discover contoso.com.

    SQL Server uses SSSD and NSS for mapping user accounts and groups to security identifiers (SIDs). SSSD must be configured and running for SQL Server to create AD logins successfully. realmd usually does this automatically as part of joining the domain, but in some cases, you must do this separately.

    For more information, see how to configure SSSD manually, and configure NSS to work with SSSD.

  4. Verify that you can now gather information about a user from the domain, and that you can acquire a Kerberos ticket as that user. The following example uses id, kinit, and klist commands for this.

    id user@contoso.com
    
    uid=1348601103(user@contoso.com) gid=1348600513(domain group@contoso.com) groups=1348600513(domain group@contoso.com)
    
    kinit user@CONTOSO.COM
    
    Password for user@CONTOSO.COM:
    
    klist
    Ticket cache: FILE:/tmp/krb5cc_1000
    Default principal: user@CONTOSO.COM
    

    Note

    • If **id user@contoso.com** returns, No such user, make sure that the SSSD service started successfully by running the command sudo systemctl status sssd. If the service is running and you still see the error, try enabling verbose logging for SSSD. For more information, see the Red Hat documentation for Troubleshooting SSSD.

    • If **kinit user@CONTOSO.COM** returns, KDC reply did not match expectations while getting initial credentials, make sure you specified the realm in uppercase.

For more information, see the Red Hat documentation for Discovering and Joining Identity Domains.

Option 2: Use third-party openldap provider utilities

You can use third-party utilities such as PBIS, VAS, or Centrify. This article does not cover steps for each individual utility. You must first use one of these utilities to join the Linux host for SQL Server to the domain before continuing forward.

SQL Server does not use third-party integrator's code or library for any AD-related queries. SQL Server always queries AD using openldap library calls directly in this setup. The third-party integrators are only used to join the Linux host to AD domain, and SQL Server does not have any direct communication with these utilities.

Important

Please see the recommendations for using the mssql-conf network.disablesssd configuration option in the Additional configuration options section of the article Use Active Directory authentication with SQL Server on Linux.

Verify that your /etc/krb5.conf is configured correctly. For most third-party Active Directory providers, this configuration is done automatically. However, check /etc/krb5.conf for the following values to prevent any future issues:

[libdefaults]
default_realm = CONTOSO.COM

[realms]
CONTOSO.COM = {
}

[domain_realm]
contoso.com = CONTOSO.COM
.contoso.com = CONTOSO.COM

Check that the reverse DNS is properly configured

The following command should return the fully qualified domain name (FQDN) of the host that runs SQL Server. An example is SqlHost.contoso.com.

host **<IP address of SQL Server host>**

The output of this command should be similar to **<reversed IP address>**.in-addr.arpa domain name pointer SqlHost.contoso.com. If this command does not return your host's FQDN, or if the FQDN is incorrect, add a reverse DNS entry for your SQL Server on Linux host to your DNS server.

Next steps

This article covers the prerequisite of how to configure a SQL Server on a Linux host machine with Active Directory Authentication. To finish configuring SQL Server on Linux to support Active Directory accounts, follow the instructions at Use Active Directory authentication with SQL Server on Linux.