Windows Servers

Join Linux to Active Directory with realmd and SSSD

By NileVPS Team · Published · 4 min read

اقرأ المقال بالعربي

If your organisation already manages users in Active Directory, giving every Linux server its own set of local accounts quickly becomes a mess: passwords drift, people who left still have access, and nobody knows who can log in where. Joining Linux servers to the domain lets users sign in with their AD credentials, and lets you control access with AD groups. The standard way to do this today is realmd with SSSD, and it takes only a few commands once the prerequisites are right.

Prerequisites

Most failed joins come from one of these four, so check them first:

  1. DNS: the Linux server must resolve the domain's SRV records, which means using the domain controllers as DNS servers. Test with host -t SRV _ldap._tcp.corp.example.com.
  2. Time: Kerberos rejects requests when clocks differ by more than five minutes by default. Run chrony or systemd-timesyncd and point it at a domain controller. Our guide on Windows NTP servers explains how domain time works.
  3. Network access from the Linux server to the domain controllers:
PortProtocolService
53TCP/UDPDNS
88TCP/UDPKerberos
389TCP/UDPLDAP
464TCP/UDPKerberos password change
636TCPLDAPS (if used)
3268TCPGlobal Catalog
  1. An account allowed to join computers to the domain, such as a domain admin or a delegated account.

Never expose these AD ports to the public internet. Keep domain controllers and members on a private network or a VPN, or restrict the ports with a firewall to your own server addresses. Also keep the Linux hostname to 15 characters or fewer, since AD computer names have a NetBIOS limit.

In the examples below the domain is corp.example.com; replace it with yours.

Step 1: Install the packages

On Ubuntu or Debian:

sudo apt update
sudo apt install realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit krb5-user

If the Kerberos package asks for a default realm, enter the domain in capitals, for example CORP.EXAMPLE.COM.

On Rocky Linux, AlmaLinux or RHEL:

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

Step 2: Discover the domain

realm discover corp.example.com

The output should show the domain type (kerberos), the server software (active-directory) and the packages it needs. If discovery fails, the problem is almost always DNS.

Step 3: Join

sudo realm join -U Administrator corp.example.com

You are asked for the account's password. To place the computer object in a specific organisational unit, add --computer-ou="OU=Linux,OU=Servers,DC=corp,DC=example,DC=com".

Confirm the result:

realm list
id [email protected]

If id returns the user and their groups, SSSD is working. You can also test Kerberos directly with kinit [email protected] followed by klist.

Step 4: Create home folders automatically

Domain users do not have a home directory on the server until one is created. Enable automatic creation at first login:

# Ubuntu / Debian
sudo pam-auth-update --enable mkhomedir

# RHEL family
sudo authselect select sssd with-mkhomedir --force
sudo systemctl enable --now oddjobd

Step 5: Adjust SSSD settings

The configuration lives in /etc/sssd/sssd.conf. Two settings are commonly changed:

[domain/corp.example.com]
use_fully_qualified_names = False
fallback_homedir = /home/%u

With use_fully_qualified_names = False, users log in as jsmith instead of [email protected]. Keep the file permissions at 600, then apply the change:

sudo systemctl restart sssd

If you change name formats after users have already logged in, clearing the cache with sudo sss_cache -E helps.

Step 6: Control who can log in

By default every domain user may be able to log in, which is rarely what you want. Restrict access to specific groups:

sudo realm deny --all
sudo realm permit -g "Linux [email protected]"

Grant sudo through a file in /etc/sudoers.d/, edited with visudo:

sudo visudo -f /etc/sudoers.d/ad-admins
%linux\ admins ALL=(ALL:ALL) ALL

Spaces in group names are escaped with a backslash. If you kept fully qualified names, use the full form, for example %linux\ [email protected].

Finally, test an SSH login as a domain user from another terminal before closing your current session. SSH must use PAM (UsePAM yes, the default on most distributions) for SSSD logins to work.

Troubleshooting

  • "Couldn't join realm" or "No such realm found": DNS is not pointing at the domain controllers.
  • "Clock skew too great": fix time synchronisation and retry.
  • `id` works but SSH login is denied: check realm permit rules and /var/log/auth.log (Debian family) or /var/log/secure (RHEL family).
  • Slow logins: often DNS reverse lookups or unreachable domain controllers; check journalctl -u sssd.

To leave the domain cleanly, run sudo realm leave corp.example.com. If you do not have a domain yet, start with our guide to installing Active Directory.

FAQ

Do I need Samba to join Linux to Active Directory?

Not for logins. realmd, SSSD and adcli handle the join and authentication; the Samba packages listed above only provide helper tools. A full Samba server is needed only if the Linux machine will share files with Windows clients.

Can domain users log in to Linux with SSH keys?

Yes. You can keep keys in each user's ~/.ssh/authorized_keys as usual, or store public keys in an AD attribute and have SSSD supply them to SSH through sss_ssh_authorizedkeys. Password logins still go through SSSD and Kerberos.

What happens if the domain controller is unreachable?

SSSD caches credentials of users who have logged in before, so they can usually still sign in while the domain controller is offline. Users who have never logged in to that server cannot, so keep at least two domain controllers if Linux logins matter.

Related guides