Your submission was sent successfully! Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

NT4 Domain Controller (legacy)

Note:
This documentation has moved to a new home! Please update your bookmarks to the new URL for the up-to-date version of this page.

Note:
This section is flagged as legacy because nowadays, Samba can be deployed in full Active Directory domain controller mode, and the old-style NT4 Primary Domain Controller is deprecated.

A Samba server can be configured to appear as a Windows NT4-style domain controller. A major advantage of this configuration is the ability to centralise user and machine credentials. Samba can also use multiple backends to store the user information.

Primary domain controller

In this section, we’ll install and configure Samba as a Primary Domain Controller (PDC) using the default smbpasswd backend.

Install Samba

First, we’ll install Samba, and libpam-winbind (to sync the user accounts), by entering the following in a terminal prompt:

sudo apt install samba libpam-winbind

Configure Samba

Next, we’ll configure Samba by editing /etc/samba/smb.conf. The security mode should be set to user, and the workgroup should relate to your organization:

workgroup = EXAMPLE
...
security = user

In the commented “Domains” section, add or uncomment the following (the last line has been split to fit the format of this document):

domain logons = yes
logon path = \\%N\%U\profile
logon drive = H:
logon home = \\%N\%U
logon script = logon.cmd
add machine script = sudo /usr/sbin/useradd -N -g machines -c Machine -d
      /var/lib/samba -s /bin/false %u

Note:
If you wish to not use Roaming Profiles leave the logon home and logon path options commented out.

  • domain logons
    Provides the netlogon service, causing Samba to act as a domain controller.

  • logon path
    Places the user’s Windows profile into their home directory. It is also possible to configure a [profiles] share placing all profiles under a single directory.

  • logon drive
    Specifies the home directory local path.

  • logon home
    Specifies the home directory location.

  • logon script
    Determines the script to be run locally once a user has logged in. The script needs to be placed in the [netlogon] share.

  • add machine script
    A script that will automatically create the Machine Trust Account needed for a workstation to join the domain.

In this example the machines group will need to be created using the addgroup utility (see Security - Users: Adding and Deleting Users for details).

Mapping shares

Uncomment the [homes] share to allow the logon home to be mapped:

[homes]
   comment = Home Directories
   browseable = no
   read only = no
   create mask = 0700
   directory mask = 0700
   valid users = %S

When configured as a domain controller, a [netlogon] share needs to be configured. To enable the share, uncomment:

[netlogon]
   comment = Network Logon Service
   path = /srv/samba/netlogon
   guest ok = yes
   read only = yes
   share modes = no

Note:
The original netlogon share path is /home/samba/netlogon, but according to the Filesystem Hierarchy Standard (FHS), /srv is the correct location for site-specific data provided by the system.

Now create the netlogon directory, and an empty (for now) logon.cmd script file:

sudo mkdir -p /srv/samba/netlogon
sudo touch /srv/samba/netlogon/logon.cmd

You can enter any normal Windows logon script commands in logon.cmd to customise the client’s environment.

Restart Samba to enable the new domain controller, using the following command:

sudo systemctl restart smbd.service nmbd.service

Final setup tasks

Lastly, there are a few additional commands needed to set up the appropriate rights.

Since root is disabled by default, a system group needs to be mapped to the Windows Domain Admins group in order to join a workstation to the domain. Using the net utility, from a terminal enter:

sudo net groupmap add ntgroup="Domain Admins" unixgroup=sysadmin rid=512 type=d

You should change sysadmin to whichever group you prefer. Also, the user joining the domain needs to be a member of the sysadmin group, as well as a member of the system admin group. The admin group allows sudo use.

If the user does not have Samba credentials yet, you can add them with the smbpasswd utility. Change the sysadmin username appropriately:

sudo smbpasswd -a sysadmin

Also, rights need to be explicitly provided to the Domain Admins group to allow the add machine script (and other admin functions) to work. This is achieved by executing:

net rpc rights grant -U sysadmin "EXAMPLE\Domain Admins" SeMachineAccountPrivilege \
SePrintOperatorPrivilege SeAddUsersPrivilege SeDiskOperatorPrivilege \
SeRemoteShutdownPrivilege

You should now be able to join Windows clients to the Domain in the same manner as joining them to an NT4 domain running on a Windows server.

Backup domain controller

With a Primary Domain Controller (PDC) on the network it is best to have a Backup Domain Controller (BDC) as well. This will allow clients to authenticate in case the PDC becomes unavailable.

When configuring Samba as a BDC you need a way to sync account information with the PDC. There are multiple ways of accomplishing this; secure copy protocol (SCP), rsync, or by using LDAP as the passdb backend.

Using LDAP is the most robust way to sync account information, because both domain controllers can use the same information in real time. However, setting up an LDAP server may be overly complicated for a small number of user and computer accounts. See Samba - OpenLDAP Backend for details.

First, install samba and libpam-winbind. From a terminal enter:

sudo apt install samba libpam-winbind

Now, edit /etc/samba/smb.conf and uncomment the following in the [global]:

workgroup = EXAMPLE
...
security = user

In the commented Domains uncomment or add:

domain logons = yes
domain master = no

Make sure a user has rights to read the files in /var/lib/samba. For example, to allow users in the admin group to SCP the files, enter:

sudo chgrp -R admin /var/lib/samba

Next, sync the user accounts, using SCP to copy the /var/lib/samba directory from the PDC:

sudo scp -r username@pdc:/var/lib/samba /var/lib

You can replace username with a valid username and pdc with the hostname or IP address of your actual PDC.

Finally, restart samba:

sudo systemctl restart smbd.service nmbd.service

You can test that your Backup Domain Controller is working by first stopping the Samba daemon on the PDC – then try to log in to a Windows client joined to the domain.

Another thing to keep in mind is if you have configured the logon home option as a directory on the PDC, and the PDC becomes unavailable, access to the user’s Home drive will also be unavailable. For this reason it is best to configure the logon home to reside on a separate file server from the PDC and BDC.

Further reading

This page was last modified 3 months ago. Help improve this document in the forum.