Setting up Samba as an Active Directory Domain Controller: Difference between revisions

From SambaWiki
(Condensed the wiki a lot, moving some things to their own pages.)
(→‎Setup a basic File Share: note adding fileshares are optional, and add some more notes after discussion on samba mailing list)
Line 223: Line 223:
The [[Configure_NTP|Configure NTP]] page includes the full NTP configuration process and the SELinux policies.
The [[Configure_NTP|Configure NTP]] page includes the full NTP configuration process and the SELinux policies.

== Setup a basic File Share ==
== Setup a basic File Share (Optional) ==

The provisioning will create a very simple <tt>/usr/local/samba/etc/smb.conf</tt> file with no non-system shares by
The provisioning will create a very simple <tt>/usr/local/samba/etc/smb.conf</tt> file with no non-system shares by default. The system sysvol and netlogon shares should be created for you , as these are needed for a domain controller.

default. For the server to be useful you, will need to update it to
If you are also using the server as a file server, or you have some other reason to share files then you should create such shares as needed. For example:
have at least one share. For example:


Revision as of 23:26, 15 April 2013

HOWTO to set up Samba as an Active Directory compatible Domain Controller

This document explains how to setup a simple Samba server as a Domain Controller compatible with Microsoft's Active Directory, for use particularly by Microsoft Windows clients that are joined to the Active Directory Domain, for services such as Domain Logon. We refer to this capability as being an AD DC for short.

Video Demonstrations of This HOWTO

A set of demonstration videos is available that may provide a useful overview of the contents of this HOWTO.

A Note on Versions

Samba is developing rapidly. This HOWTO is frequently updated to reflect the latest changes in the Samba git repository. Please see the Samba 4.0 Release Planning for more specifics on the release planning.

Please review the Release Notes for the version you have installed, it may contain important information not yet reflected in this HOWTO.

Installing Samba

You will either need to install samba from a your distributions package manager or Build Samba. At this time the packages are generally older and very hard to support due to the rapid development of the samba project, so it is recommended to build from source.


If you are upgrading from a previous release of Samba 4.x, be sure to review all the Release Notes for the new version, as well as the notes for all the interim versions.

If you are upgrading from source please refer to the upgrading a source version otherwise please consult your distributions upgrade procedure.

Server Information

For the rest of this tutorial, we will be using the following configuration for our example AD DC configuration.

 Installation Directory: /usr/local/samba
 Server Hostname: samba (Your linux hostname will be used here)
 DNS Domain Name: (This will also be your realm)
 NT4 Domain Name: samdom
 IP Address:
 Server Role: DC

Step 1: Provision Samba

The provision step sets up a basic user database, and is used when you are setting up your Samba server in its own domain. If you instead want to setup your Samba server as an additional domain controller in an existing domain, then please see the Joining a Windows Domain Controller as an Additional DC in a Domain section on this page. If you want to migrate an existing Samba 3.x domain to Samba 4.0 as an AD DC, see the Migrating an Existing Samba 3 Domain to Samba 4 section on this page.

The provision step must be run as a user with permission to write to the install directory.

 # /usr/local/samba/bin/samba-tool domain provision

This will run the provision tool interactively. For realm use something like, for domain (it should suggest this) use samdom.

If you run the previous command with a user who does not have write permission to the install directory, you will get an error similar to this:

tdb_open_ex: could not open file /usr/local/samba/private/sam.ldb.d/DC=SAMDOM,DC=EXAMPLE,DC=COM. ldb: Permission denied

You can pass options to samba-tool domain provision command. You can run it with the --help option to see a list of them.

  • Note: As of Samba 4.0.0 RC1 the provision command now uses Samba's internal DNS server by default, if you would like the older behavior, add --dns-backend=BIND9_DLZ or --dns-backend=BIND_FLATFILE to the above provision command.
  • Note: You may need to remove the /usr/local/samba/etc/smb.conf file if you are re-running the provision command.
  • Note: If you use the --adminpass='password' switch, be aware that there are password complexity requirements, so if you are getting some odd error with provision, try a more complex password ie. 'Pa$$w0rd'
  • Note: If you have a "password complexity" failure during domain provisioning - read the following! The password complexity requirement is at least one uppercase letter, and one number, and at least eight characters long. If you don't use a complex enough password, the provision script will error, and you will need to delete the /usr/local/samba/private and /usr/local/samba/etc directories, then run samba-tool domain provision again - with a better password.

Step 2: Starting your Samba AD DC

If you are planning to run Samba as a production server, then just run the samba binary as root

# /usr/local/samba/sbin/samba

That will run Samba in 'standard' mode, which is suitable for production use. Samba doesn't yet have init scripts included for each platform, but making one for your platform should not be difficult. There are some example scripts (for RedHat/Fedora, Debian and Ubuntu) on the Samba4/InitScript page.

If you are running Samba as a developer you may find the following more useful:

# /usr/local/samba/sbin/samba -i -M single

This will start samba with all log messages printed to stdout, and restricting it to a single process. That mode of operation makes debugging samba with gdb easier.

If you want to launch it under gdb, run samba as follows:

# gdb --args /usr/local/samba/sbin/samba -i -M single

Note that if you are running any Samba 3 smbd or nmbd processes they need to be stopped before starting samba from Samba 4.

Take care when running Samba commands if you also have a previous version of Samba installed. To avoid inadvertently running the wrong version, you should consider putting the /usr/local/samba/bin and /usr/local/samba/sbin directories in the beginning of your PATH variable.

You can see what version of Samba, if any, is in your PATH variable by running the following:

# samba -V

Step 3: Testing connectivity to your Samba AD DC

First check you have the right version of smbclient by running the following command:

 $ /usr/local/samba/bin/smbclient --version

This should show you a version starting with "Version 4.0.XXXXX".

Now run this command to list the shares on your Samba server:

$ /usr/local/samba/bin/smbclient -L localhost -U%

The output of the command should be similar to what is shown below:

       Sharename       Type      Comment
       ---------       ----      -------
       netlogon        Disk
       sysvol          Disk
       IPC$            IPC       IPC Service (Samba 4.0.0)

The netlogon and sysvol shares are basic shares needed for Active Directory server operation.

If the command failed, restart samba by running the following:

# killall samba
# /usr/local/samba/sbin/samba

To test that authentication is working, you should try to connect to the netlogon share using the Administrator password you set earlier:

$ smbclient //localhost/netlogon -UAdministrator%'p4$$word' -c 'ls'

The output of the command should be similar to what is shown below:

Domain=[SAMDOM] OS=[Unix] Server=[Samba 4.0.0]
  .                                   D        0  Wed Sep 12 21:00:36 2012
  ..                                  D        0  Wed Sep 12 21:02:28 2012

Step 4: Configure DNS

A working DNS setup is essential to the correct operation of Samba. Without the right DNS entries, Kerberos won't work, which in turn means that many of the basic features of Samba won't work.

It is worth spending some extra time to ensure your DNS setup is correct, as debugging problems caused by mis-configured DNS can take a lot of time later on.

Samba's Internal DNS Server

If you specified --dns-backend=SAMBA_INTERNAL or did not specify any backend at all when you provisioned, there is no further setup required for the DNS server, however you used any other --dns-backend= option in your provision line see using bind as your dns backend for additional setup instructions. After you have dns configured, you still need to configure your /etc/resolv.conf as shown in Configure /etc/resolv.conf

If you want the internal DNS server to forward requests it isn't responsible for, then add the following to your smb.conf:

 dns forwarder = {IP-Address of the DNS you want to forward to}

Warning: If you are running X windows on your machine, networkmanager could be spawning dnsmasq or if you are using another DNS server, check the logs for lines like:


If you need to disable this you can open /etc/NetworkManager/NetworkManager.conf in your favorite editor as root, and comment out the line dns=dnsmasq, then restart network-manager

Configure /etc/resolv.conf

For all the local DNS lookups to resolve correctly, we need to modify the server's /etc/resolv.conf file. The following example should be sufficient to have DNS resolve properly:

  • Note: Remember to change the IP Address to your Samba server's IP Address
  • Note: If your server is set up to receive its IP configuration via DHCP, the /etc/resolv.conf file might be automatically updated. Refer to your distribution's documentation on how to stop this behavior.

Testing DNS

To test that DNS is working properly, run the following commands and compare the output to what is shown:

$ host -t SRV has SRV record 0 100 389
$ host -t SRV has SRV record 0 100 88
$ host -t A has address

The answers you get should be similar to the ones above (adjusted for your DNS domain name and hostname). If you get any errors, carefully check your system logs to locate the problem.

Step 5: Configure Kerberos

Kerberos configuration is handled by the krb5.conf file. This file is typically located in the /etc directory, please refer to your distribution documentation for the location of this file on your system. There is a sample file located at /usr/local/samba/share/setup/krb5.conf that is a suitable replacement for an existing file. This file is generated by provision and will look similar to the following:

    default_realm = SAMDOM.EXAMPLE.COM
    dns_lookup_realm = false
    dns_lookup_kdc = true
  • Note: If you have forgotten your realm, running samba-tool testparm --suppress-prompt | grep realm will let you know what you used.

Testing Kerberos

The simplest test is to use the kinit command as follows:

$ kinit administrator@SAMDOM.EXAMPLE.COM
  • Note: You must specify your domain realm SAMDOM.EXAMPLE.COM in uppercase letters
  • Note: Depending on your distribution kinit may just return you to a prompt, however, some distributions may return something like Warning: Your password will expire in 41 days on Thu Mar 28 04:38:35 2013.

To verify that Kerberos is working, and that you received a ticket, run the following:

$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: administrator@SAMDOM.EXAMPLE.COM
Valid starting     Expires            Service principal
02/10/13 19:39:48  02/11/13 19:39:46  krbtgt/SAMDOM.EXAMPLE.COM@SAMDOM.EXAMPLE.COM

If either kinit or klist do not exist on your system, refer to Samba_4_OS_Requirements on how to install the necessary packages.

You can also test Kerberos form a remote client, but you must first configure the client's krb5.conf and resolve.conf as shown previously.

  • Note: If you are using a client behind NAT then you have to add the following to the krb5.conf on the domain controller server:
    check-ticket-addresses = false
  • Note: If provision generated you a password and you forgot it or didn't get it saved in some way, you can use "samba-tool user setpassword administrator" as root to reset it.

Configure NTP (Optional)

The Configure NTP page includes the full NTP configuration process and the SELinux policies.

Setup a basic File Share (Optional)

The provisioning will create a very simple /usr/local/samba/etc/smb.conf file with no non-system shares by default. The system sysvol and netlogon shares should be created for you , as these are needed for a domain controller.

If you are also using the server as a file server, or you have some other reason to share files then you should create such shares as needed. For example:

      path = /data/test
      comment = Test Share
      read only = no
  • Note: You will need to restart Samba to make new shares visible.

Setup a Printer share

You can also Setup a printer share for samba.

Configure a Windows Client to join our Samba Active Directory

Configuring a windows client to join our domain is useful when you need to start connecting windows clients.

Samba AD management

You can manage your Samba AD just like a windows AD using the windows tools by using the following link Samba AD Management from windows

You may also want to use the linux command line, so you can add users with samba-tool as well.

Joining a Windows Domain Controller as an Additional DC in a Domain

Once you have a Samba domain controller set up, you can choose to join additional domain controllers to the domain, whether they be additional Samba domain controllers, or additional Windows domain controllers.

If you wish to join an additional Samba domain controller to a domain, then please see the Joining a domain as a DC page. The instructions on that page are the same for joining Samba to a Windows domain as they are for joining Samba to an existing Samba domain.

If you wish to join a new Windows domain controller to a Samba domain, then you should use the 'dcpromo' tool on the Windows machine. Please see the normal instructions for installing dcpromo on Windows, with the exception that you should not check the 'DNS server' option box when it is offered. Right now you should either use Windows for DNS, or use Samba and bind9 for DNS. Mixing the two can work, but it is an advanced topic that is beyond the scope of this howto.

Backup and Recovery of a Samba AD DC

See the Samba Backup and Recovery howto.

Migrating an Existing Samba Domain to Samba

It is very likely that you already have a running Samba3 domain on your network. The question is, how do you migrate that domain and all of its users and machines over to a new Samba 4 based domain without having to move every user profile and machine to the new domain? The answer is the samba-tool domain classicupgrade function.

Connecting other services to your new/migrated Active Directory

If you finished setting up or migrating to Samba 4, you maybe want to connect other services to your new Active Directory. Have a look at the Beyond Samba page.

Setup your firewall

If you are setting up samba to work with your firewall, check out the configure your firewall page.

Report Your Success/Failure!

Samba, as a replicating domain controller, is still developing rapidly. We'd like to hear from users about their successes and failures. We would encourage you to report both your successes and failures to the samba-technical mailing list on