Setting up Samba as an Active Directory Domain Controller

From SambaWiki
Revision as of 06:32, 10 February 2010 by AndrewTridgell (talk | contribs)

Samba4 HOWTO

tridge@samba.org, December 2004

Updates:

 asn@redhat.com, December 2009
 tridge@samba.org, February 2010 (for alpha11)

This is a very basic document on how to setup a simple Samba4 server. This is aimed at people who are already familiar with Samba3 and wish to participate in Samba4 development or test the alpha releases of Samba4. This is not aimed at general production use of Samba4, although some brave sites are running Samba4 in production based on these instructions.

Step 1: Download Samba4

If you have downloaded the Samba4 code via a tarball released from the samba.org website, Step 1 has already been completed for you. For testing with the version released in the tarball, you may continue on to Step 2.

Note that the references below to the top-level directory named "samba-master" will instead be based on the name of the tarball downloaded (e.g. "samba-4.0.0alpha3" for the tarball samba-4.0.0alpha3.tar.gz). Also note that in the "master" branch the samba4 code is located in in the "source4/" subdirectory (it was in "source/" subdirectory in the "v4-0-test" branch).

There are 2 methods of doing this:

  • via git
  • via rsync

Both methods will create a directory called "samba-master" in the current directory. If you don't have rsync or git then install one of them.

If you have a choice, we strongly recommend using the git method for downloading Samba, as it makes getting updates easier, and also allows you to integrate test patches from Samba developers more easily in case of problems.

git

 $ git clone git://git.samba.org/samba.git samba-master; cd samba-master

If you want to update the tree to the latest version run:

 $ git pull

rsync

 $ rsync -avz samba.org::ftp/unpacked/samba_4_0_test/ samba-master

Note that the above rsync command will give you a checked out git repository, but it's is missing all git objects. To turn it into a working git repository you need to do the following steps:

 $ cd samba-master/
 $ rm .git/objects/info/alternates
 $ rm .git/refs/tags/*
 $ rm -r .git/refs/remotes/
 $ git config remote.origin.url git://git.samba.org/samba.git
 $ git config --add remote.origin.fetch +refs/tags/*:refs/tags/* (this line is optional)
 $ git fetch

Note you can ignore this error from git fetch: error: refs/heads/master does not point to a valid object!

Also note that the git fetch will download the complete git history (about 160 MB with all the tags and about 125 MB without old tags).

You can update it to the latest version at some future date using:

 $ git pull


Step 2: Compile Samba4

Recommended optional development libraries:

  • acl and xattr development libraries (libattr1-dev package in Debian/Ubuntu)
  • blkid development libraries (libblkid-dev package in Debian/Ubuntu)
  • gnutls (libgnutls-dev package in Debian/Ubuntu)
  • readline (libreadline5-dev package in Debian/Ubuntu)
  • Python development libraries (python-dev in Debian/Ubuntu) required to compile

For Fedora:

$ yum install libacl-devel libblkid-devel gnutls-devel readline-devel python-devel

Since only released versions of Samba contain a pre-generated configure script, you will have to generate it by hand if you downloaded the source with rsync or git:

$ cd samba-master/source4
$ ./autogen.sh

Run this:

 $ cd samba-master/source4
 $ ./configure.developer
 $ make

The above command will setup Samba4 to install in /usr/local/samba. If you want Samba to install somewhere else then you should use the --prefix option to configure.developer.

The reason we recommend using configure.developer rather than configure for Samba4 alpha releases is that it will include extra debug information that will help us diagnose problems in case of failures. It will also allow you to run the various builtin automatic tests.

After building Samba, we recommend that you run

 $ make quicktest

That will run a short (approximately 2 minute) set of tests to validate your build of Samba. While we try to be careful to ensure that all builds of Samba in the git repository are usable, sometimes a bug slips through, and 'make quicktest' is a fast way of checking that your build passes basic tests.

The output of 'make quicktest' should end in a "ALL OK" message. If it doesn't, then please ask on the samba-technical mailing list or the #samba-technical IRC channel.

Step 3: Install Samba4

Run this as a user who have permission to write to the install directory (which defaults to /usr/local/samba). Use --prefix option to configure.developer above to change this.

 $ make install

For the rest of this HOWTO we will assume that you have installed Samba4 in the default location, which is /usr/local/samba.

Step 4: Provision Samba4

The "provision" step sets up a basic user database, and is used when you are setting up your Samba4 server in its own domain. If you instead want to setup your Samba4 server as an additional domain controller in an existing domain, then please see the separate page on Samba4 joining a domain.

In the following examples we will assume your DNS domain name is 'samdom.example.com' and your short (also known as NT4) domain name is 'samdom'. We will assume that your Samba servers hostname is sambaserver.

It must be run as a user with permission to write to the install directory.

 $ cd samba-master/source4
 $ ./setup/provision --realm=samdom.example.com --domain=SAMDOM --adminpass=SOMEPASSWORD --server-role='domain controller'

Troubleshooting note: you may need to rm the smb.conf file if you failed to pass valid names and provision previously failed

There are many other options you can pass to the 'provision' command, run it with the --help option to see a list of them.

Step 5: Starting Samba4

If you are planning to run Samba4 as a production server, then just run the "samba" binary.

 $ samba

That will run Samba4 in 'standard' mode, which is suitable for production use. Samba4 alpha11 doesn't yet have init scripts included for each platform, but making one for your platform should not be difficult.

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

 $ samba -i -M single

that means start "samba" with messages in stdout, and running a single process. That mode of operation makes debugging "samba" with gdb particularly easy. If you want to launch it under gdb, then the following example could be useful:

 $ sudo gdb --args bin/samba -i -M single

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

Make sure you put the bin and sbin directories from your new install in your $PATH or you may end up running the wrong version. You can see what version you have by running "samba -V".

Note: in older developer versions of samba4 "samba" was still called "smbd".

Step 6: Testing Samba4

Try this command:

 $ smbclient -L localhost -U%

That should show you a list of shares available on your server. For example:

       Sharename       Type       Comment
       ---------       ----       -------
       test            Disk
       netlogon        Disk
       sysvol          Disk
       IPC$            IPC        IPC Service (Samba 4.0.0alpha12-GIT-5e755e9)
       ADMIN$          Disk       DISK Service (Samba 4.0.0alpha12-GIT-5e755e9)

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

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%PASSWORD

You should get a "smb>" prompt, and access to your netlogon directory.

Step 7 Create a share in smb.conf

The provisioning will create a very simple smb.conf with no shares by default. For the server to be useful you will need to update it to have at least one share. For example:

 [test]
       path = /data/test
       read only = no


Step 8 Configure DNS

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

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

The simplest way to get a working DNS setup for Samba4 is to start with the DNS zone and configuration files that are created by the 'provision' step above. If you look in /usr/local/samba/private directory, you'll find a file called 'named.conf' and another one called samdom.example.com.zone (adjusted for your real DNS domain name of course!).

Assuming your have a bind9 DNS server installed, you can activate the configuration that the provision has created by adding a line like this to /etc/bind/named.conf.local:

 include "/usr/local/samba/private/named.conf";

After adding that line you should restart your bind server and check in the system logs for any problems.

One common problem is that many modern Linux distributions activate 'Apparmor' or 'SELinux' by default, and these may be configured to deny access to bind for your the named.conf and zone files created in the provision. If your bind logs show that bind is getting a access denied error acccessing these files then please see your local system documentation for how to enable access to these files in bind (hint: for Apparmor systems such as Ubuntu, the command aa-logprof may be useful).

Now you need to test that DNS is working correctly. Check that your /etc/resolv.conf is pointing correctly at your local DNS server, then run the following commands:

 $ host -t SRV _ldap._tcp.samdom.example.com.
 _ldap._tcp.samdom.example.com has SRV record 0 100 389 blu.samdom.example.com.
 $ host -t SRV _kerberos._udp.samdom.example.com.
 _kerberos._udp.samdom.example.com has SRV record 0 100 88 blu.samdom.example.com.
 $ host -t A sambaserver.samdom.example.com.
 sambaserver.samdom.example.com has address 10.0.0.1

Check that you get answers similar to the ones above (adjusted for your DNS domain name and hostname). If you get any errors then carefully check your system logs to find and fix the problem.

Step 9 (Optional): Configure kerberos DNS dynamic updates

Configuring your server to allow for dynamic DNS updates is a more advanced topic, so if this is the first time you are installing Samba4 then we suggest that you skip it.

If you do want to configure DNS on the Samba server to support dynamic update, then this is what you need to do.

First, follow the previous step to get a basic non-dynamic DNS setup working, and make sure you have tested it and it works.

For dynamic updates, have a look at the generated named.conf for your domain in /usr/local/samba/private/named.conf. You will notice that it contains a section called 'update-policy' which controls dynamic updates. Read the comments in that section carefully and edit if necessary.

Now you need to tell bind how to find the kerberos keytab file to allow it to check kerberos signatures on incoming DNS update requests. On most modern systems that is done by adding the following lines to /etc/default/bind:

 KEYTAB_FILE="/usr/local/samba/private/dns.keytab"
 KRB5_KTNAME="/usr/local/samba/private/dns.keytab"
 export KEYTAB_FILE
 export KRB5_KTNAME

The reason for setting both variables is to cope with different versions of the kerberos libraries that you may have installed.

Now you have to ensure that bind can read this file, which may involve changes in Apparmor or SELinux configuration, and the right ownership and file permissions for bind. A sensible set of permissions would be something like this:

 -rw-r----- 1 root bind 986 2010-02-10 17:22 /usr/local/samba/private/dns.keytab


  1. Bind has to be able to update the journal files. The easiest, laziest, and worst way to do this is by 'chown -R bind.bind /etc/bind"; this is totally insecure, but since you're just testing that's okay...for the moment. The correct way to do it is to create the journal files by hand and change their ownership to bind.bind, OR put the journals in a seperate directory (like /var/bind/dynamic or something) and change it's ownership.
  2. For PTR registration to work correctly, the name server entry in the SOA record (see here for the synthax) for the reverse zone has to be the name of valid DNS server in your domain otherwise Windows is unable to make the PTR registration
  3. Restart bind
  4. `tail -n 30 /var/log/daemon.log` and check for any errors regarding the zone files. You may have to do some tweaking.

Note: If you decide to test bind via something like `named -d 9999 -f -g`, remember to run the "EXPORT KRB5_KTNAME..." line beforehand, or it will fail with a GSS/"File Not Found" error.

Assuming it's all up and working, test the DNS resolution. You should be able to do `dig _ldap._tcp.dc._msdcs.your.realm SRV @localhost` And get something back. For instance, on mine:

samba4-alpha5:~# dig _ldap._tcp.dc._msdcs.samba5.local SRV @localhost

; <<>> DiG 9.5.0 <<>> _ldap._tcp.dc._msdcs.samba5.local SRV @localhost
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1550
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;_ldap._tcp.dc._msdcs.samba5.local. IN  SRV

;; ANSWER SECTION:
_ldap._tcp.dc._msdcs.samba5.local. 604800 IN SRV 0 100 389 samba4-alpha5.samba5.local.

DNS should be set to go. Read on for joining workstations to the domain.

Note2: Windows clients must be configured to send signed DNS update as it is not always the default, to have PTR record update you need to activate the registration of this kind of record.

Both can be done it either through GPO or local policy editor using this policy files, see this kb article for more information.

NOTE about filesystem support

To use the advanced features of Samba4 you need a filesystem that supports both the "user" and "system" xattr namespaces.

If you run Linux with a 2.6 kernel and ext3 this means you need to include the option "user_xattr" in your /etc/fstab. For example:

/dev/hda3 /home ext3 user_xattr 1 1

You also need to compile your kernel with the XATTR and SECURITY options for your filesystem. For ext3 that means you need:

  CONFIG_EXT3_FS_XATTR=y
  CONFIG_EXT3_FS_SECURITY=y

If you are running a Linux 2.6 kernel with CONFIG_IKCONFIG_PROC defined you can check this with the following command:

  $ zgrep CONFIG_EXT3_FS /proc/config.gz

If you don't have a filesystem with xattr support, then you can simulate it by using the option:

  posix:eadb = /usr/local/samba/eadb.tdb

that will place all extra file attributes (NT ACLs, DOS EAs, streams etc), in that tdb. It is not efficient, and doesn't scale well, but at least it gives you a choice when you don't have a modern filesystem.

Testing your filesystem

To test your filesystem support, install the 'attr' package and run the following 4 commands as root:

 # touch test.txt
 # setfattr -n user.test -v test test.txt
 # setfattr -n security.test -v test2 test.txt
 # getfattr -d test.txt
 # getfattr -n security.test -d test.txt

You should see output like this:

 # file: test.txt
 user.test="test"
 # file: test.txt
 security.test="test2"

If you get any "Operation not supported" errors then it means your kernel is not configured correctly, or your filesystem is not mounted with the right options.

If you get any "Operation not permitted" errors then it probably means you didn't try the test as root.

Configure a Windows Client to join a Samba 4 Active Directory

Active Directory is a powerful administration service which enables an administrator to centrally manage a network of Windows 2000, Windows XP Pro, Windows 2003, and Windows Vista Business Edition effectively. To test the real Samba 4 capability, we use Windows XP Pro as testing environment (Windows XP Home doesn't include Active Directory functionality and won't work).

To allow Samba 4 Active Directory or Microsoft Active Directory to manage a computer, we need to join the computer into the active directory. It involves:

  1. Configuring DNS Setting
  2. Configuring date/time and time zone
  3. Joining the domain

Step 1: Configure DNS Setting for Windows

Before we configure the DNS setting, verify that you are able to ping the Server's IP Address. If you are not able to ping the server, double check your IP address, firewall, routing, etc.

Once you have verified network connectivity between the Samba server and client,

  1. Right Click My Network Places -> Properties
  2. Double click local area network->Properties
  3. Double click tcp/ip
  4. Use static dns server, add the Samba 4 server's ip address inside the primary dns server column. Image:http://www.extraknowledge.org/xoops/images/samba/dnsclient.jpg
  5. Press ok, ok, ok again until finished.
  6. Open a command prompt, type 'ping servername.your.realm' (change to suit your custom realm per your provision)

If you get replies, then it means your Windows XP settings are correct (for DNS) and Samba4 Server's DNS services is working as well.

Step 2: Configure date/time and time zone

Active Directory uses Kerberos as the backend for authentication. Kerberos requires that the system clock on the client and server be synchronized to within a few seconds of each other. If they are not synchronized, authentication will fail for apparently no reason.

  1. Change the timezone in Windows XP Pro so that server and client using same time zone. In my computer, I use Asia/Kuala_Lumpur (I come from Malaysia).Image:http://www.extraknowledge.org/xoops/images/samba/timezone.jpg
  2. Change the date/time so the client have same HH:MM with the server Image:http://www.extraknowledge.org/xoops/images/samba/time.jpg

Step 3: Joining the Windows client into domain

Now your Windows is ready to join the Active Directory (AD) domain,

As administrator:-

  1. Right Click my Computer-> Properties
  2. Choose Computer Name, click change..
  3. Click option 'Domain', insert YOUR.REALM (if you failed, try YOURDOM)(Image:http://www.extraknowledge.org/xoops/images/samba/joindomain.jpg
  4. When it request username/password, type administrator as username, SOMEPASSWORD as password (per your earlier provision).
  5. It will tell you the Windows XP has successfully join into Active Directory Domain, and you need to restart.
  6. After restart, you should get the normal domain logon dialog
  7. Choose domain YOURDOM, insert username administrator as username, SOMEPASSWORD as password (again, per your earlier provision)
  8. If you login successfully, then you able to enjoy samba 4 active directory services at next section.

Viewing Samba 4 Active Directory object from Windows XP Pro

Due to Samba 4 SWAT is not yet ready for production, we need install windows 2003 adminpak into windows XP in order to manage the domain(It is user friendly). Before begin, make sure the domain administrator have administrative right to control your computer.(To give any user administrative right, in Windows XP Pro, right click my computer, press manage-> choose groups-> doble click administrators and add members from domain into the member list. During you add member from active directory as member, it will prompt you to enter active directory username/password).

Step 1: Installing Windows Remote Administration Tools onto Windows

Vista

Downlod the Windows Remote Administration Tools from

 http://www.microsoft.com/downloads/details.aspx?FamilyId=9FF6E897-23CE-4A36-B7FC-D52065DE9960&displaylang=en

and follow the "Install RSAT" instruction desribed at

 http://support.microsoft.com/kb/941314

Windows XP Pro

  1. In Windows XP, download adminpak and supporttools from
 http://www.microsoft.com/downloads/details.aspx?FamilyID=c16ae515-c8f4-47ef-a1e4-a8dcbacff8e3&displaylang=en
 http://download.microsoft.com/download/3/e/4/3e438f5e-24ef-4637-abd1-981341d349c7/WindowsServer2003-KB892777-SupportTools-x86-ENU.exe

  1. Run through the installation.
  2. Press start->run, type 'dsa.msc', if a window 'active directory users and computers' prompt up, it mean you had install adminpak it successfully. You can also find this at Start>Programs>Administrative Tools, which should have a lot more items now.
  3. Go to c:\Program Files\Support Tools to check whether the support tools were installed correctly; if yes, then your XP workstation is ready to manage the Samba 4 Active Directory.

Step 2: Viewing samba 4 active directory content

  1. Login as domain 'testing1.org' administrator, press start->run.
  2. type dsa.msc
  1. Expand the testing1.org tree to see existing object in domain. Image:http://www.extraknowledge.org/xoops/images/samba/dsa.msc.jpg

Managing Samba 4 Active Directory From Windows XP Pro

One of Samba4's goals is to integrate with (and replace) Active Directory as a system. At this point, if everything has worked correctly you should have an "Administrative Tools" menu under Programs. If, under Administrative Tools you have "Active Directory Users and Computers", that is a very good sign. Most times, if there is a configuration or bug in Samba4, the AD Users & Computers (among other interfaces) won't show up as an option. You can run it by hand (Start->Run->dsa.msc) but it's unlikely to work correctly.


Step 1: Adding user into Samba 4 Active Directory

Just as with Samba 3, version 4 needs an existing Unix user to map the Samba user to. Basically this task involve 3 jobs.

  1. Add Unix User. In most Linux systems, you can use the useradd command. As root:
    useradd demo
    passwd demo (Will prompt for a new password)
    
    (Debian/Ubuntu users tend to use the adduser script, which is an interactive script that handles both user addition and the password)


NOTE: As of Alpha3, SWAT is disabled and you will not be able to add users through the web interface. If you are using Alpha3 (April 2008), or possibly later, step two here will not work. Instead, use Step 2B.

  1. Using SWAT to add samba user.
    1. Open up mozilla-firefox
    2. open url http://samba-4-server-ip:901
    3. User = administrator, password = testing1, domain = testing,->Login.
    4. click installation-> new user.
    5. type username=demo, unix name = demo, password you like twice
    1. Go into your Samba4 source tree (cd samba4/source) and run ./bin/net newuser username

NOTE: As of Alpha 5, creating users correctly puts them into the AD side of things. After performing step, check in the AD Users & Computer setup to verify if the user you created is present. If it is, try logging in as the new user on the workstation. If it works, ignore the next step.

Modify the user from Windows XP.

    1. Start -> run -> dsa.msc
    2. Open testing1.org tree, click container 'users'-> double click 'demo'.
    3. Edit first name, lastname and username Image:http://www.extraknowledge.org/xoops/images/samba/dsa.msc-general.jpg
    4. Go to account tab, fill in 'demo' in both username and logon name, choose domain (not the pre-win 2000) column.
    1. set 'Password never expires' if you'd like.
    2. Apply, then try to login with new user.


If you able to login, then the user was successfully created.

Step 2: Adding groups into Samba 4 Active Directory

To manage resource more effectively, we need to use groups. Same with users we need to have a unix group and samba groups. I haven't test whether the groups is working properly, but I guess more or less this method is correct(Please feed back if you found any error).

  1. Creating Unix Groups
   $sudo groupadd grpdemo
   $sudo gedit /etc/group
   
   we can add user into group with following syntax:- 
   grpdemo:x:1007:demo, user1, user2
  1. Adding group into samba 4 active directory
    1. As domain testing1.org administrator, start->run->dsa.msc.
    2. Open tree testing1.org, right click 'users' container->new->groups
    3. type group name 'grpdemo' in both column->ok (others leave default)
  1. Link the Unix groups to samba groups
    1. Start mozilla-firefox (or IE), open url : http://samba-svr-ip:901
    2. Username=administrator, password = testing1, domain = testing1
    3. Choose preview of new swat-> modules -> LDB Browser
    4. Open up sam.ldb tree, open up dc=testing1,dc=org, open cn=users
    5. Click CN= grpdemo-> press modify button
    6. At bottom most of right side, press '+' (Which is adding a new field)
    7. Put field name(left text box) = 'unixName', data(right text box) = 'grpdemo' -> ok

Adding organization unit (ou) into samba 4 domain

Organizational Unit (ou), is a most powerful feature I found in active directory. Basically this is some kind of container which allow us to drag & drop users,computers into it.

we can link several kind of group policy (You can consider it is a graphical setting) to an ou, and the setting will deploy to all users/computers under the ou. With a single domain we can have many ou and sub ou. So the result is it greatly reduce administrative afford because we able to manage everything via ou. The implementation of group policy will discuss at next chapter.

Before we create an ou, we must know how ou look likes? By default we can see a sample ou 'Domain Controllers', it looks difference with 'users' and 'computers' container right? We can deploy group policy to users or computers container.

  1. To create an ou, as testing1 domain administrator, start -> run -> dsa.msc
  2. right click testing1.org.
  3. choose new -? organizationalunit
  4. type 'oudemo'
  5. Then you will see an new ou appear, with the name 'oudemo'.
  6. You can drag user 'demo' into the new ou (Don't move other users! Unless you want to get stuck!)
  7. Right Click the 'oudemo', you can click sub ou with method 3.

Normaly we create ou base on total department we have, what branch we have and etc. Don't confuse between groups and ou, groups use to control the permission, ou use for deploy setting to all users/computers under it.

Implementing Group Policy (GPO) into samba 4 domain

Recently Samba 4 Active Directory had support group policy, and we can create the group policy on the fly. The basic ideal of group policy is:-

  1. Group Policy have 2 kind of settings, computers and users.
  2. Computer setting apply to computer, user setting apply to user
  3. We link the group policy to particular ou, and the group policy will effect all computers/users under the ou.
  1. To add a group policy, right click 'oudemo' ou->properties
  2. Choose group policy
  3. Press new, name as 'gpoudemo'
  4. Press edit to edit the policy.
  5. Here will demonstrate how to block user from access the control panel. Open the tree 'User Configuration'->'control paner'.
  6. Double click prohibit access to the control panel
  7. Press enable and then press ok. Now the all users under 'oudemo' won't able to access the control panel.
  8. Make sure user demo is inside the 'oudemo'(You can drag and drop it).
  9. Logout and login as user 'demo'
  10. You'll find user demo not able to access control panel
 * User configuration will effect once we logout and login.
 * Computer configuration will effect once restart computer

To learn more about managing and implementing organizational units, group policy, and active directory Google for Windows 2003 Active Directory implementation.