Sub topic 18
Joining Samba to a domain
Earlier chapters built a standalone Samba server. It keeps its own user list, and you add each person with smbpasswd. That works for a handful of users. In an organization that already runs Active Directory (AD), it means maintaining every account twice. This chapter shows how to make the Samba server a domain member, so AD handles authentication and Samba serves files.
Prerequisites
This chapter assumes you can:
- write a working
smb.confwith a share, as in the earlier chapters; - manage services with
systemctl; - read DNS and time settings on a Linux host.
You also need an AD domain and an account that is allowed to join machines. This chapter uses the realm EXAMPLE.COM and the NetBIOS domain EXAMPLE.
What changes in a domain member
A domain member does not store passwords for domain users. It sends authentication to a domain controller (DC) using Kerberos or NTLM. The winbindd daemon does the translation work:
- It asks the DC about users and groups.
- It maps each Windows security identifier (SID) to a local UID or GID, because the Linux kernel only understands numbers.
- It exposes the result to the system through the Name Service Switch (NSS), so
getentand file ownership work for domain accounts.
| Setting | Standalone server | Domain member |
|---|---|---|
| `server role` | `standalone server` | `member server` |
| `security` | `user` (default) | `ads` |
| Password store | Samba's own database | The domain controller |
| UID/GID source | Local `/etc/passwd` | `winbindd` via idmap |
The following diagram shows what happens when a user connects.
Prepare DNS and time
Joins fail more often because of DNS and time than because of Samba. Check both before you touch smb.conf.
- The server must use a DNS server that can resolve the AD domain, usually the DC itself. Test with
host -t SRV _ldap._tcp.example.com. - Kerberos rejects tickets when clocks differ by more than five minutes by default. Point the server at the same time source as the DC, for example with
chronyc trackingto check synchronization. - The server needs a stable hostname. The
net ads joincommand registers it in AD.
Install packages and configure
Install the winbind and Kerberos packages. On Debian-family systems:
sudo apt install samba winbind libnss-winbind libpam-winbind krb5-userOn Red Hat-family systems:
sudo dnf install samba samba-winbind samba-winbind-clients krb5-workstationThen replace the [global] section of /etc/samba/smb.conf:
[global]
workgroup = EXAMPLE
realm = EXAMPLE.COM
security = ads
server role = member server
kerberos method = secrets and keytab
idmap config * : backend = tdb
idmap config * : range = 3000-7999
idmap config EXAMPLE : backend = rid
idmap config EXAMPLE : range = 10000-999999
winbind use default domain = yes
winbind refresh tickets = yes
template shell = /bin/bash
template homedir = /home/%U
[projects]
path = /srv/samba/projects
read only = no
valid users = @"EXAMPLE\Domain Users"
create mask = 0664
directory mask = 0775The workgroup value is the short NetBIOS name of the domain. The realm is the DNS name in uppercase. The two must match what AD uses.
Choosing an idmap backend
The idmap config lines decide which UID or GID each SID receives. Two rules apply to all backends. The ranges must not overlap, and they must stay stable once files exist, because file ownership on disk stores the numbers.
| Backend | How it assigns IDs | Typical use |
|---|---|---|
| `tdb` | Hands out the next free number and remembers it locally | The default domain `*` only |
| `rid` | Computes the ID from the SID's relative ID (RID) plus the range start | One server, or several servers with identical settings |
| `ad` | Reads `uidNumber` and `gidNumber` attributes stored in AD | Environments where UIDs must match across servers and NFS |
With rid, two servers produce the same UIDs only if they use the same range for the same domain. With ad, the numbers live in the directory, so they agree everywhere. If the same users also reach files over NFS, ad is the safer choice, because NFS maps by number (see the identity mapping chapter).
Join the domain
Edit /etc/nsswitch.conf so the system asks winbind about users and groups:
passwd: files winbind
group: files winbindThen join, restart the services, and verify:
sudo net ads join -U Administrator
sudo systemctl restart smbd nmbd winbind
sudo net ads testjoin
wbinfo -t
wbinfo -u
getent passwd aliceOn Red Hat-family systems, the unit names are smb, nmbd, and winbind. Here is what each check tells you:
net ads testjoinconfirms the machine account is valid.wbinfo -tchecks the trust secret between the server and the domain.wbinfo -ulists domain users.getent passwd aliceproves NSS integration. Ifwbinfo -uworks butgetentdoes not, the problem isnsswitch.conf.
Because of winbind use default domain = yes, you write alice instead of EXAMPLE\alice. Without that setting, every name needs the domain prefix, including inside valid users.
Set permissions on the shared directory
File ownership still follows normal Linux rules. Give the domain group access to the directory, and keep the setgid bit so new files inherit the group:
sudo mkdir -p /srv/samba/projects
sudo chgrp "EXAMPLE\\Domain Users" /srv/samba/projects
sudo chmod 2775 /srv/samba/projectsThe valid users line controls who may connect. The directory mode controls what they may do after they connect. Both must allow the access.
Common failures
- Join fails with a DNS error. The server cannot find the DC's SRV records. Fix the resolver first.
- Join or login fails with "clock skew too great". Synchronize time.
wbinfo -uworks,getent passwdis empty. Addwinbindtopasswdandgroupinnsswitch.conf.- Users can connect but get "permission denied". Check the directory group and mode with
ls -ld, and check SELinux labels withls -Zon Red Hat-family systems. - Everything fails after a reboot. Confirm
winbindis enabled, not only started.
Exercise
A domain member shows correct output for wbinfo -u, but ls -l on files in a share shows numeric owners instead of names. Which file would you check first, and why?
Show answer
Check /etc/nsswitch.conf. wbinfo talks to winbindd directly, so it works even when NSS is not configured. ls -l resolves names through NSS, so the passwd and group lines need winbind added. After you fix it, getent passwd alice should return an entry.
Exercise
Two Samba servers join the same domain and share the same SAN storage. Both use the rid backend. Users report that files created through one server look owned by the wrong person on the other. What is the likely cause, and what are two ways to fix it?
Show answer
The two servers use different idmap config EXAMPLE : range values, so the same SID becomes different UIDs. One fix is to give both servers the identical range. The other is to switch to the ad backend so that the UIDs come from AD attributes and agree everywhere. In either case, existing files may need chown to the correct numbers.