Skip to content

Active Directory

Simple AD domain with multiple domain controllers and file server
Section titled “Simple AD domain with multiple domain controllers and file server”

We will install a single-domain Active Directory infrastructure using Debian or Ubuntu Servers.

  • 2 Domain Controllers and 1 File Server.
  • Windows workstations will be able to join the domain.
  • No license costs, except for the Windows workstation licenses.
  • Domain Name: 386387.XYZ

  • Domain NetBIOS Name: 386387

  • First DC:

    • srv1.386387.xyz
    • 192.168.1.201
    • Debian 13/12 or Ubuntu 24.04/22.04 LTS Server
  • Second DC:

    • srv2.386387.xyz
    • 192.168.1.202
    • Debian 13/12 or Ubuntu 24.04/22.04 LTS Server
  • File Server:

    • filesrv.386387.xyz
    • 192.168.1.203
    • Debian 13/12 or Ubuntu 24.04/22.04 LTS Server
  • Windows workstations will be able to connect to the domain.

  • Groups and Users:

    • Marketing: mrk01, mrk02, mrk03
    • Sales: sls01, sls02, sls03
    • Production: prd01, prd02, prd03
    • IT: it01, it02, it03, support
    • SysAdmin: support
    • All: all of the above users
  • File Server Shares:

Terminal window
//filesrv/Xmrk01 mrk01 (RW)
//filesrv/Xmrk02 mrk02 (RW)
//filesrv/Xmrk03 mrk03 (RW)
//filesrv/XMrk Marketing (RW)
//filesrv/XMrkPub Marketing (RW), All (R)
//filesrv/Xsls01 sls01 (RW)
//filesrv/Xsls02 sls02 (RW)
//filesrv/Xsls03 sls03 (RW)
//filesrv/XSls Sales (RW)
//filesrv/XSlsPub Sales (RW), All (R)
//filesrv/Xprd01 prd01 (RW)
//filesrv/Xprd02 prd02 (RW)
//filesrv/Xprd03 prd03 (RW)
//filesrv/XPrd Production (RW)
//filesrv/XPrdPub Production (RW), All (R)
//filesrv/Xit01 it01 (RW)
//filesrv/Xit02 it02 (RW)
//filesrv/Xit03 it03 (RW)
//filesrv/Xsupport support (RW)
//filesrv/XIT IT (RW)
//filesrv/XITPub IT (RW), All (R)
//filesrv/XSys SysAdmin (RW)
//filesrv/XSysPub SysAdmin (RW), All (R)
//filesrv/XAll All (RW)

In my tests, I used distributions uniformly (i.e., all servers were either Debian 12, Debian 13, Ubuntu 22.04, or Ubuntu 24.04). I believe the system would work with a mix of distributions, but this has not been tested.

  • Add First DC (srv1.386387.xyz)
  • Add Additional DC (srv2.386387.xyz)
  • AD User Management
  • Add a Linux File Server to the Domain (filesrv.386387.xyz)
  • Add a Windows Computer to the Domain

There are some important considerations. Not complying with them can cause problems.

The Realm is in the domain name format, and the Domain Name is a single word (the NetBIOS name of your domain).

If your company’s internet domain name is example.com, you can choose your Realm and Domain Name as follows:

  • Realm: EXAMPLE.COM
  • Domain Name: EXAMPLE

Whenever you use them, they must be in UPPERCASE. This is due to a design choice in Microsoft’s implementation.

0.3.2. IP Address and Hostname for Domain Controllers and Domain Members

Section titled “0.3.2. IP Address and Hostname for Domain Controllers and Domain Members”

Domain Controllers and Domain Members should have static IP addresses.

While there might be ways to use DHCP, it is not recommended for Domain Controllers, and the method is beyond this guide’s scope.

The hostname must be in the format name.example.com (lowercase). Due to an incompatibility between Samba and Debian/Ubuntu (and other Debian-based distributions), you must remove the line starting with 127.0.1.1 (not 127.0.0.1) from your /etc/hosts file and add the server’s IP and hostname (both short and FQDN) as shown below.

Example /etc/hosts:

127.0.0.1 localhost
192.168.1.201 srv1.386387.xyz srv1

You should have at least 2 Domain Controllers (DCs). You could use one Windows and one Linux DC to benefit from Microsoft’s native AD management tools, but this is not necessary.

I recommend installing all DCs on Linux and using a Windows workstation with RSAT (Remote Server Administration Tools) installed to manage AD. This allows you to use the standard AD management programs (including for DNS) from a familiar environment.

Remember to replace all occurrences of 386387, 386387.XYZ, and 386387.xyz with your own values, respecting the case.



Domain Name: 386387
Realm: 386387.XYZ
Hostname: srv1.386387.xyz
IP: 192.168.1.201

Set the hostname to the fully qualified domain name (if not done already):

Terminal window
sudo hostnamectl hostname srv1.386387.xyz

Update the /etc/hosts file

Terminal window
sudo nano /etc/hosts

Modify the beginning of the file as follows:

127.0.0.1 localhost
192.168.1.201 srv1.386387.xyz srv1
Terminal window
sudo apt update
sudo apt -y install samba krb5-config winbind smbclient

Provide the following answers to the configuration prompts:

  • Default Kerberos version 5 realm: 386387.XYZ
  • Kerberos servers for your realm: srv1.386387.xyz
  • Administrative server for your Kerberos realm: srv1.386387.xyz

Backup the original samba configuration:

Terminal window
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.original

Run the domain provisioning tool:

Terminal window
sudo samba-tool domain provision

Provide the following answers:

  • Realm: 386387.XYZ
  • Domain: 386387
  • Server Role (dc, member, standalone) [dc]: Press Enter
  • DNS backend (SAMBA_INTERNAL,…: Press Enter
  • DNS forwarder IP address…: Enter your DNS server (e.g., 8.8.8.8)
  • Administrator password: Enter a strong password

1.4. Copy Kerberos Config, Stop and Disable Services

Section titled “1.4. Copy Kerberos Config, Stop and Disable Services”
Terminal window
sudo cp /var/lib/samba/private/krb5.conf /etc/
sudo systemctl stop smbd nmbd winbind systemd-resolved
sudo systemctl disable smbd nmbd winbind systemd-resolved
sudo systemctl unmask samba-ad-dc

Note: On Debian 12, you may see an error Failed to stop systemd-resolved.service: Unit systemd-resolved.service not loaded. This can be safely ignored.

Terminal window
sudo rm /etc/resolv.conf
sudo nano /etc/resolv.conf

Add the following lines:

domain 386387.xyz
nameserver 127.0.0.1
Terminal window
sudo systemctl start samba-ad-dc
sudo systemctl enable samba-ad-dc

Check the domain functional level:

Terminal window
sudo samba-tool domain level show

Create a test domain user:

Terminal window
sudo samba-tool user create exforge


Domain Name: 386387
Realm: 386387.XYZ
Hostname: srv2.386387.xyz
IP: 192.168.1.202
Original DC: srv1.386387.xyz (192.168.1.201)

Set hostname as fully qualified (if you haven’t done it before)

Terminal window
sudo hostnamectl hostname srv2.386387.xyz

Update the /etc/hosts file

Terminal window
sudo nano /etc/hosts

Modify the beginning of the file as follows:

127.0.0.1 localhost
192.168.1.202 srv2.386387.xyz srv2

2.2. Install Kerberos and Edit Configuration

Section titled “2.2. Install Kerberos and Edit Configuration”
Terminal window
sudo apt update
sudo apt -y install krb5-user

(Press Enter through all prompts; we will configure manually.)

Edit the Kerberos configuration:

Terminal window
sudo nano /etc/krb5.conf

Ensure the beginning of the file contains:

[libdefaults]
default_realm = 386387.XYZ
dns_lookup_realm = false
dns_lookup_kdc = true

This step is typically not necessary for Debian 12/13.

Terminal window
sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved
Terminal window
sudo rm /etc/resolv.conf
sudo nano /etc/resolv.conf

Add the following lines (pointing to the first DC):

domain 386387.xyz
nameserver 192.168.1.201

You will be prompted for the Domain Administrator password (set during provisioning in section 1.3).

Terminal window
sudo kinit administrator

Verify the Kerberos ticket:

Terminal window
sudo klist

Install necessary packages:

Terminal window
sudo apt -y install samba winbind smbclient

Back up and remove the default Samba config, then join the domain:

Terminal window
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.org
sudo samba-tool domain join 386387.XYZ DC -U "srv1\administrator" \
--dns-backend=SAMBA_INTERNAL

2.7. Stop, Disable Old Services, and Enable Samba AD DC

Section titled “2.7. Stop, Disable Old Services, and Enable Samba AD DC”
Terminal window
sudo systemctl stop smbd nmbd winbind
sudo systemctl disable smbd nmbd winbind
sudo systemctl unmask samba-ad-dc
sudo systemctl start samba-ad-dc
sudo systemctl enable samba-ad-dc

Verify authentication locally:

Terminal window
sudo smbclient //127.0.0.1/netlogon -U Administrator -c 'ls'

Check replication status:

Terminal window
sudo samba-tool drs showrepl

Note: The warning Warning: No NC replicated for Connection! is not critical and can be ignored initially.



These commands can be run on any Domain Controller.

View all user-related commands:

Terminal window
sudo samba-tool user --help

List domain users:

Terminal window
sudo samba-tool user list

List users with full Distinguished Name (DN):

Terminal window
sudo samba-tool user list --full-dn

Create a domain user:

Terminal window
sudo samba-tool user create ubuntu

Create a user forced to change password at next login:

Terminal window
sudo samba-tool user create ubuntu2 --must-change-at-next-login

Delete a domain user:

Terminal window
sudo samba-tool user delete ubuntu2

Reset a user’s password:

Terminal window
sudo samba-tool user setpassword ubuntu

Set an expiration date for a user account:

Terminal window
sudo samba-tool user setexpiry ubuntu --days=7

Remove expiration from a user account:

Terminal window
sudo samba-tool user setexpiry --noexpiry ubuntu

Disable/Enable a user account:

Terminal window
sudo samba-tool user disable ubuntu
sudo samba-tool user enable ubuntu

Show user details:

Terminal window
sudo samba-tool user show ubuntu

Edit user details (opens in a text editor):

Terminal window
sudo samba-tool user edit ubuntu

View all group-related commands:

Terminal window
sudo samba-tool group --help

List domain groups:

Terminal window
sudo samba-tool group list

List members of a specific group:

Terminal window
sudo samba-tool group listmembers "Domain Users"

Create a new domain group:

Terminal window
sudo samba-tool group add TestUsers
sudo samba-tool group add TestUsers2

Delete a domain group:

Terminal window
sudo samba-tool group delete TestUsers2

Add/Remove a member to/from a group:

Terminal window
sudo samba-tool group addmembers TestUsers ubuntu
sudo samba-tool group removemembers TestUsers ubuntu

Show group details:

Terminal window
sudo samba-tool group show TestUsers

Edit group details (opens in a text editor):

Terminal window
sudo samba-tool group edit TestUsers

View all computer-related commands:

Terminal window
sudo samba-tool computer --help

List domain computers:

Terminal window
sudo samba-tool computer list

Show computer details:

Terminal window
sudo samba-tool computer show srv1

Edit computer details (opens in a text editor):

Terminal window
sudo samba-tool computer edit srv1

3.4. Other Important Management Subcommands

Section titled “3.4. Other Important Management Subcommands”

Check the local AD database for errors:

Terminal window
sudo samba-tool dbcheck --help

Manage delegation:

Terminal window
sudo samba-tool delegation --help

Manage DNS:

Terminal window
sudo samba-tool dns --help

Domain management:

Terminal window
sudo samba-tool domain --help

Manage Directory Replication Services (DRS):

Terminal window
sudo samba-tool drs --help

Forest management:

Terminal window
sudo samba-tool forest --help

Manage Flexible Single Master Operations (FSMO) roles:

Terminal window
sudo samba-tool fsmo --help

Manage Group Policy Objects (GPO):

Terminal window
sudo samba-tool gpo --help

Manage Organizational Units (OU):

Terminal window
sudo samba-tool ou --help

Schema querying and management:

Terminal window
sudo samba-tool schema --help

Sites management:

Terminal window
sudo samba-tool sites --help

Retrieve the time from a server:

Terminal window
sudo samba-tool time --help


Create all users with Password1 as the default password. Users will be required to change their password at first logon.

Terminal window
sudo samba-tool user add mrk01 Password1 --given-name=Mrk --surname=01 \
--must-change-at-next-login
sudo samba-tool user add mrk02 Password1 --given-name=Mrk --surname=02 \
--must-change-at-next-login
sudo samba-tool user add mrk03 Password1 --given-name=Mrk --surname=03 \
--must-change-at-next-login
sudo samba-tool user add sls01 Password1 --given-name=Sls --surname=01 \
--must-change-at-next-login
sudo samba-tool user add sls02 Password1 --given-name=Sls --surname=02 \
--must-change-at-next-login
sudo samba-tool user add sls03 Password1 --given-name=Sls --surname=03 \
--must-change-at-next-login
sudo samba-tool user add prd01 Password1 --given-name=Prd --surname=01 \
--must-change-at-next-login
sudo samba-tool user add prd02 Password1 --given-name=Prd --surname=02 \
--must-change-at-next-login
sudo samba-tool user add prd03 Password1 --given-name=Prd --surname=03 \
--must-change-at-next-login
sudo samba-tool user add it01 Password1 --given-name=IT --surname=01 \
--must-change-at-next-login
sudo samba-tool user add it02 Password1 --given-name=IT --surname=02 \
--must-change-at-next-login
sudo samba-tool user add it03 Password1 --given-name=IT --surname=03 \
--must-change-at-next-login
sudo samba-tool user add support Password1 --given-name=Support --surname=User \
--must-change-at-next-login
Terminal window
sudo samba-tool group add Marketing
sudo samba-tool group add Sales
sudo samba-tool group add Production
sudo samba-tool group add IT
sudo samba-tool group add SysAdmin
sudo samba-tool group add All

4.3. Add Users to the Corresponding Groups

Section titled “4.3. Add Users to the Corresponding Groups”
Terminal window
sudo samba-tool group addmembers Marketing mrk01,mrk02,mrk03
sudo samba-tool group addmembers Sales sls01,sls02,sls03
sudo samba-tool group addmembers Production prd01,prd02,prd03
sudo samba-tool group addmembers IT it01,it02,it03,support
sudo samba-tool group addmembers SysAdmin support
sudo samba-tool group addmembers All Marketing,Sales,Production,IT,SysAdmin


Set the hostname:

Terminal window
sudo hostnamectl hostname filesrv.386387.xyz

Update /etc/hosts:

Terminal window
sudo nano /etc/hosts

Modify the beginning of the file:

127.0.0.1 localhost
192.168.1.203 filesrv.386387.xyz filesrv

Recreate /etc/resolv.conf:

Terminal window
sudo rm /etc/resolv.conf
sudo nano /etc/resolv.conf

Add:

domain 386387.xyz
nameserver 192.168.1.201
nameserver 192.168.1.202
Terminal window
sudo apt update
sudo apt -y install winbind libpam-winbind libnss-winbind krb5-config \
samba-dsdb-modules samba-vfs-modules

Provide the following answers if prompted:

  • Default Kerberos version 5 realm: 386387.XYZ
  • Kerberos servers for your realm: srv1.386387.xyz
  • Administrative server for your Kerberos realm: srv1.386387.xyz
Terminal window
sudo nano /etc/samba/smb.conf

Add/Modify the following lines in the [global] section:

workgroup = 386387
realm = 386387.XYZ
security = ads
idmap config * : backend = tdb
idmap config * : range = 3000-7999
idmap config 386387 : backend = rid
idmap config 386387 : range = 10000-999999
template homedir = /home/%U
template shell = /bin/bash
winbind use default domain = true
winbind offline logon = false

5.3.2. Configure PAM to Create Home Directories

Section titled “5.3.2. Configure PAM to Create Home Directories”
Terminal window
sudo nano /etc/pam.d/common-session

Add the following line:

session optional pam_mkhomedir.so skel=/etc/skel umask=077

Join the server to the domain:

Terminal window
sudo net ads join -U Administrator

Restart the winbind service:

Terminal window
sudo systemctl restart winbind

Verify domain users are visible:

Terminal window
sudo wbinfo -u

There will be 24 shares. Create the directory structure:

Terminal window
sudo mkdir -p /srv/shares/{Xmrk01,Xmrk02,Xmrk03,XMrk,XMrkPub,Xsls01,Xsls02,Xsls03,XSls,XSlsPub,Xprd01,Xprd02,Xprd03,XPrd,XPrdPub,Xit01,Xit02,Xit03,Xsupport,XIT,XITPub,XSys,XSysPub,XAll}

Set initial permissions (more specific permissions will be set via Samba):

Terminal window
sudo chmod -R 777 /srv/shares
Terminal window
sudo apt -y install samba
Terminal window
sudo nano /etc/samba/smb.conf

Add the following lines to the [global] section:

netbios name = filesrv
socket options = TCP_NODELAY SO_RCVBUF=16384 SO_SNDBUF=16384
idmap uid = 10000-20000
winbind enum users = yes
winbind gid = 10000-20000
os level = 20
winbind enum groups = yes
password server = *
preferred master = no
winbind separator = +
encrypt passwords = yes
dns proxy = no
wins server = 192.168.1.201
wins proxy = no

Add the following share definitions to the end of the file. Remember to replace 386387 with your domain NetBIOS name if different.

# Marketing
[Xmrk01]
comment = Xmrk01
path = /srv/shares/Xmrk01
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = mrk01
write list = mrk01
[Xmrk02]
comment = Xmrk02
path = /srv/shares/Xmrk02
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = mrk02
write list = mrk02
[Xmrk03]
comment = Xmrk03
path = /srv/shares/Xmrk03
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = mrk03
write list = mrk03
[XMrk]
comment = XMrk
path = /srv/shares/XMrk
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @Marketing
write list = @Marketing
[XMrkPub]
comment = XMrkPub
path = /srv/shares/XMrkPub
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @Marketing, @All
read list = @All
write list = @Marketing
# Sales
[Xsls01]
comment = Xsls01
path = /srv/shares/Xsls01
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = sls01
write list = sls01
[Xsls02]
comment = Xsls02
path = /srv/shares/Xsls02
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = sls02
write list = sls02
[Xsls03]
comment = Xsls03
path = /srv/shares/Xsls03
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = sls03
write list = sls03
[XSls]
comment = XSls
path = /srv/shares/XSls
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @Sales
write list = @Sales
[XSlsPub]
comment = XSlsPub
path = /srv/shares/XSlsPub
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @Sales, @All
read list = @All
write list = @Sales
# Production
[Xprd01]
comment = Xprd01
path = /srv/shares/Xprd01
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = prd01
write list = prd01
[Xprd02]
comment = Xprd02
path = /srv/shares/Xprd02
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = prd02
write list = prd02
[Xprd03]
comment = Xprd03
path = /srv/shares/Xprd03
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = prd03
write list = prd03
[XPrd]
comment = XPrd
path = /srv/shares/XPrd
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @Production
write list = @Production
[XPrdPub]
comment = XPrdPub
path = /srv/shares/XPrdPub
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @Production, @All
read list = @All
write list = @Production
# IT
[Xit01]
comment = Xit01
path = /srv/shares/Xit01
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = it01
write list = it01
[Xit02]
comment = Xit02
path = /srv/shares/Xit02
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = it02
write list = it02
[Xit03]
comment = Xit03
path = /srv/shares/Xit03
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = it03
write list = it03
[Xsupport]
comment = Xsupport
path = /srv/shares/Xsupport
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = support
write list = support
[XIT]
comment = XIT
path = /srv/shares/XIT
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @IT
write list = @IT
[XITPub]
comment = XITPub
path = /srv/shares/XITPub
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @IT, @All
read list = @All
write list = @IT
# All
[XAll]
comment = XAll
path = /srv/shares/XAll
browseable = yes
read only = no
create mask = 770
directory mask = 770
valid users = @All
write list = @All
Terminal window
sudo systemctl restart smbd


  1. On the Windows computer, configure its DNS settings to point to your Domain Controllers (e.g., 192.168.1.201 and 192.168.1.202).
  2. Proceed with the standard “Join a Domain” process through System Properties, using the domain name (386387) and an administrative account.
  3. After joining, you can install RSAT (Remote Server Administration Tools) on the Windows workstation to manage AD, DNS, and other services.
  4. You can connect to the file shares using \\filesrv\ShareName (e.g., \\filesrv\XMrk) from any domain-joined Windows computer.