How to Join Fedora Server to Microsoft Active Directory Using realmd and SSSD

Fedora tutorial - IT technology blog
Fedora tutorial - IT technology blog

Comparing Linux Integration Solutions for Active Directory

Managing local user accounts across dozens of standalone Linux servers frequently leads to permission creep and orphaned accounts. When an employee departs, logging into every server individually to purge local accounts is both tedious and a significant security risk. Leveraging existing Active Directory (AD) infrastructure for centralized identity management is the most sensible path forward.

When integrating a Fedora Server into a Windows domain, system administrators typically weigh three primary options:

  • Using Winbind (Samba stack): The traditional method deeply tied to Samba. Winbind communicates with the Domain Controller (DC) via MSRPC and NTLM, making it the most suitable choice if your server must serve files over the CIFS/SMB protocol.
  • Manual OpenLDAP + Kerberos (krb5) + PAM Integration: Assembling every building block by hand. Kerberos handles identity authentication, LDAP performs user and group authorization queries, and PAM along with NSS bridges everything into the Linux OS.
  • Combining realmd and SSSD (System Security Services Daemon): The modern standard championed by Red Hat. The realmd utility automates the entire domain discovery and join workflow. Underneath, the sssd daemon maintains sessions, queries identity data, and handles local caching.

Pros and Cons of Each Approach

1. Winbind

Pros: Excellent compatibility with complex Samba file shares and legacy systems that still rely on NTLMv2.

Cons: The smb.conf configuration file is bloated and complex. When a domain exceeds 10,000 objects, user resolution performance through Winbind often degrades noticeably.

2. Manual OpenLDAP and Kerberos Configuration

Pros: Offers granular control over custom schema attributes tailored to unique organizational requirements.

Cons: Exceptionally high risk of misconfiguration. You must maintain multiple files such as /etc/krb5.conf, /etc/nsswitch.conf, and configurations in /etc/pam.d/. A single PAM syntax mistake can lock you out of SSH sessions instantly.

3. The realmd and SSSD Duo

Pros: Extremely streamlined operation. Joining the domain takes just a single command. Configuration files for Kerberos and SSSD are generated automatically with best practices. Most importantly, SSSD delivers superior offline caching. Even during a complete network outage to your Domain Controllers, users can continue logging in seamlessly with domain accounts.

Cons: Strictly reliant on internal DNS infrastructure, particularly proper SRV records pointing to Domain Controllers.

Why Are realmd and SSSD the Gold Standard for Fedora Server?

Fedora serves as the upstream foundation for Red Hat Enterprise Linux (RHEL). Consequently, core identity management tools such as authselect and sssd are deeply integrated and thoroughly tested on this distribution. When joining a domain with realmd, the system updates PAM profiles cleanly using authselect without conflicting with default SELinux policies.

Whether deploying Fedora as a CI/CD runner, a staging environment, or an internal database server, realmd and SSSD deliver the most stable, secure, and low-maintenance experience.

Step-by-Step Guide: Joining Fedora Server to Active Directory

Step 1: Configure DNS and Time Synchronization (NTP)

Kerberos is the primary authentication protocol in Active Directory. It strictly requires that the time drift between the Fedora Server and the Domain Controller does not exceed 300 seconds (5 minutes). Exceeding this threshold causes Kerberos ticket issuance to fail.

First, verify that your server points to internal DNS servers and resolves the domain’s SRV records (e.g., corp.local):

# Check current DNS servers
resolvectl status

# Query LDAP and Kerberos SRV records
host -t srv _ldap._tcp.corp.local
host -t srv _kerberos._tcp.corp.local

Next, ensure clock synchronization is active with chronyd:

# Enable NTP time synchronization
sudo timedatectl set-ntp true

# Verify synchronization status
timedatectl status

Step 2: Install Required Packages

Fedora’s official repositories provide all necessary packages out of the box. Install them by running:

sudo dnf install -y realmd sssd oddjob oddjob-mkhomedir adcli samba-common-tools krb5-workstation

Roles of the core packages:

  • realmd: Orchestrates domain discovery and the enrollment process.
  • sssd: Daemon managing authentication, caching, and PAM/NSS integration.
  • oddjob-mkhomedir: Automatically provisions /home/username upon the user’s first AD login.
  • adcli: Low-level tool responsible for direct administrative tasks in Active Directory.

Step 3: Discover and Join the Domain

Before joining, verify that the server can discover the Active Directory domain:

sudo realm discover corp.local

The output details the domain name, realm name, and required packages. If discovery succeeds, proceed to join the domain:

sudo realm join -U Administrator corp.local

To place the computer account into a specific Organizational Unit (OU) matching your directory structure, append the computer OU flag:

sudo realm join -U Administrator corp.local --computer-ou="OU=Linux Servers,DC=corp,DC=local"

Enter the domain administrator password when prompted. If the command finishes without errors or warnings, the server has been successfully enrolled as a Computer Object in Active Directory.

Bước 4: Kích hoạt tự động tạo Home Directory

When AD users log in via SSH for the first time, they require a dedicated directory for their profile. On Fedora, enable this safely using authselect:

# Enable mkhomedir feature in the sssd profile
sudo authselect select sssd with-mkhomedir --force

# Enable and start the oddjobd service immediately
sudo systemctl enable --now oddjobd.service

Step 5: Optimize sssd.conf and Configure sudo Permissions

By default, users must specify the full username format [email protected] to authenticate. To allow short usernames (just user), edit the SSSD configuration file:

sudo nano /etc/sssd/sssd.conf

Adjust these two directives under the [domain/corp.local] section:

# Allow login with short usernames
use_fully_qualified_names = False

# Define consistent home directory paths
fallback_homedir = /home/%u

SSSD will refuse to run if permissions on the configuration file are overly permissive. Secure file permissions and restart the daemon:

sudo chmod 600 /etc/sssd/sssd.conf
sudo systemctl restart sssd

Next, delegate sudo privileges to an AD group (such as Linux Admins). Create a dedicated drop-in file inside /etc/sudoers.d/ rather than editing /etc/sudoers directly:

sudo visudo -f /etc/sudoers.d/domain_admins

Add the following entry (use a backslash \ to escape spaces in group names):

%Linux\ Admins ALL=(ALL) ALL

Validate the syntax and set proper permissions on the sudoers drop-in file:

sudo visudo -c -f /etc/sudoers.d/domain_admins
sudo chmod 440 /etc/sudoers.d/domain_admins

Step 6: Verify Authentication and Test Offline Caching

Verify that the system can resolve identity details from Active Directory:

id devops_user

The command should return the user’s UID, primary GID, and associated AD security groups.

Now, test SSH access using the verified domain account:

ssh devops_user@<IP_FEDORA_SERVER>

The notification Creating directory '/home/devops_user'. will appear on first login. Execute sudo -i to confirm administrative access functions as intended.

To test offline caching capabilities, temporarily block outbound LDAP connectivity to your Domain Controllers using firewall rules:

sudo iptables -A OUTPUT -p tcp --dport 389 -j DROP

Establish a new SSH session with your domain credentials. The login will succeed without interruption, powered by cached credentials stored in SSSD’s local database under /var/lib/sss/db/. After testing, remove the firewall block rule.

Share: