Table of Contents#
- Prerequisites
- Installing SQL Server on Linux
- Configuring Active Directory Authentication
- Joining the Linux Machine to the AD Domain
- Configuring SQL Server for AD Authentication
- Example Usage
- Best Practices
- Common Issues and Troubleshooting
- Conclusion
- References
1. Prerequisites#
- Linux Machine: You need a Linux distribution (e.g., Ubuntu, Red Hat Enterprise Linux) with appropriate permissions to install software.
- Active Directory Domain: A functioning Active Directory domain with domain controllers.
- SQL Server Installation Media: Download the appropriate SQL Server version for Linux from the Microsoft website.
2. Installing SQL Server on Linux#
For Ubuntu#
- Update Package Lists:
sudo apt-get update- Install SQL Server:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list)"
sudo apt-get update
sudo apt-get install -y mssql-server- Configure SQL Server:
sudo /opt/mssql/bin/mssql-conf setupFollow the prompts to set the SA password and accept the license terms.
For Red Hat Enterprise Linux#
- Install SQL Server:
sudo yum install -y mssql-server- Configure SQL Server:
sudo /opt/mssql/bin/mssql-conf setupAgain, set the SA password and accept the license terms.
3. Configuring Active Directory Authentication#
Joining the Linux Machine to the AD Domain#
For Ubuntu#
- Install Required Packages:
sudo apt-get install -y realmd sssd sssd-tools adcli samba-common-bin- Join the Domain:
sudo realm join -U <domain_admin_username> <domain_name>For example:
sudo realm join -U administrator contoso.comEnter the domain admin password when prompted.
For Red Hat Enterprise Linux#
- Install Required Packages:
sudo yum install -y realmd sssd sssd-tools adcli samba-common-tools- Join the Domain:
sudo realm join -U <domain_admin_username> <domain_name>Similar to Ubuntu, enter the password when asked.
Configuring SQL Server for AD Authentication#
SQL Server on Linux does not support direct login and password settings in the [security] section of mssql.conf for Active Directory authentication. Instead, you must use the adutil tool or configure Kerberos keytab authentication.
Using adutil (Recommended)#
- Install adutil:
sudo yum install -y mssql-adutil # For RHEL
sudo apt-get install -y mssql-adutil # For Ubuntu (via Microsoft repository)- Configure AD authentication:
sudo adutil keytab create --realm <REALM> --principal <username>@<REALM> --password <password>- Enable AD authentication in mssql.conf:
Edit
/var/opt/mssql/mssql.confand add:
[network]
kerberoskeytabfile = /var/opt/mssql/krb5.keytab
[network.kerberos]
credkeytab = enabled
krbcanonicalize = enabled- Grant keytab file permissions:
sudo chown mssql:mssql /var/opt/mssql/krb5.keytab
sudo chmod 440 /var/opt/mssql/krb5.keytabAlternatively, you can configure Kerberos manually by setting up the keytab file and the [network.kerberos] section in mssql.conf. After configuration, restart SQL Server:
sudo systemctl restart mssql-server4. Example Usage#
Once configured, you can connect to SQL Server using AD credentials. For example, using the sqlcmd utility:
sqlcmd -S <server_name> -U <domain_username> -P <domain_password> -d <database_name>Replace <server_name>, <domain_username>, <domain_password>, and <database_name> with your actual values.
5. Best Practices#
- Use Least Privilege: Grant only the necessary permissions to the AD user account used for SQL Server authentication.
- Regularly Rotate Passwords: Follow your organization's password rotation policy for the AD accounts.
- Test Connectivity: Periodically test the AD authentication connection to ensure it's working as expected.
- Monitor Logs: Check the SQL Server error logs (
/var/opt/mssql/log/errorlog) and the system logs (/var/log/syslogor/var/log/messages) for any authentication-related issues.
6. Common Issues and Troubleshooting#
- Authentication Failure:
- Verify that the keytab file is properly configured and accessible by the mssql user.
- Check that the Kerberos configuration (
krb.confor/etc/krb5.conf) is correct for your AD domain. - Verify that the Linux machine is properly joined to the AD domain. You can use commands like
realm listto check the domain membership. - Ensure that the AD user has the correct permissions in SQL Server (e.g., it's a member of the appropriate database roles).
- SSSD Issues:
If there are problems with the SSSD (System Security Services Daemon) which is involved in AD authentication, check its logs (
/var/log/sssd/sssd_*.log). Common issues could be related to DNS configuration (make sure the Linux machine can resolve AD domain controllers) or incorrect SSSD configuration.
7. Conclusion#
Configuring Microsoft SQL Server Active Directory authentication on a Linux machine provides a more secure and centralized way of managing user access. By following the steps, best practices, and troubleshooting tips outlined in this blog, you can successfully set up and maintain this authentication method in your enterprise environment.