f12936a2152748e95c30e8822e5de5a565a9d84f
[sfrench/samba-autobuild/.git] / docs / docbook / projdoc / DOMAIN_MEMBER.xml
1 <chapter id="domain-member">
2
3 <chapterinfo>
4         &author.jeremy;
5         &author.jerry;
6         &author.jht;
7 </chapterinfo>
8
9 <title>Domain Membership</title>
10
11 <sect1>
12 <title>Domain Member Server</title>
13
14 <para>
15 This mode of server operation involves the samba machine being made a member
16 of a domain security context. This means by definition that all user authentication
17 will be done from a centrally defined authentication regime. The authentication
18 regime may come from an NT3/4 style (old domain technology) server, or it may be
19 provided from an Active Directory server (ADS) running on MS Windows 2000 or later.
20 </para>
21
22 <para><emphasis>
23 Of course it should be clear that the authentication back end itself could be from any
24 distributed directory architecture server that is supported by Samba. This can be
25 LDAP (from OpenLDAP), or Sun's iPlanet, of NetWare Directory Server, etc.
26 </emphasis></para>
27
28 <para>
29 Please refer to the section on Howto configure Samba as a Primary Domain Controller
30 and for more information regarding how to create a domain machine account for a
31 domain member server as well as for information regarding how to enable the samba
32 domain member machine to join the domain and to be fully trusted by it.
33 </para>
34
35 </sect1>
36
37 <sect1>
38 <title>Joining an NT4 type Domain with Samba-3</title>
39 <para><emphasis>Assumptions:</emphasis>
40 <programlisting>
41         NetBIOS name: SERV1
42         Win2K/NT domain name: DOM
43         Domain's PDC NetBIOS name: DOMPDC
44         Domain's BDC NetBIOS names: DOMBDC1 and DOMBDC2
45 </programlisting>
46 </para>
47
48 <para>First, you must edit your &smb.conf; file to tell Samba it should
49 now use domain security.</para>
50
51 <para>Change (or add) your <ulink url="smb.conf.5.html#SECURITY">
52 <parameter>security =</parameter></ulink> line in the [global] section 
53 of your &smb.conf; to read:</para>
54
55 <para><command>security = domain</command></para>
56
57 <para>Next change the <ulink url="smb.conf.5.html#WORKGROUP"><parameter>
58 workgroup =</parameter></ulink> line in the [global] section to read: </para>
59
60 <para><command>workgroup = DOM</command></para>
61
62 <para>as this is the name of the domain we are joining. </para>
63
64 <para>You must also have the parameter <ulink url="smb.conf.5.html#ENCRYPTPASSWORDS">
65 <parameter>encrypt passwords</parameter></ulink> set to <constant>yes
66 </constant> in order for your users to authenticate to the NT PDC.</para>
67
68 <para>Finally, add (or modify) a <ulink url="smb.conf.5.html#PASSWORDSERVER">
69 <parameter>password server =</parameter></ulink> line in the [global]
70 section to read: </para>
71
72 <para><command>password server = DOMPDC DOMBDC1 DOMBDC2</command></para>
73
74 <para>These are the primary and backup domain controllers Samba 
75 will attempt to contact in order to authenticate users. Samba will 
76 try to contact each of these servers in order, so you may want to 
77 rearrange this list in order to spread out the authentication load 
78 among domain controllers.</para>
79
80 <para>Alternatively, if you want smbd to automatically determine 
81 the list of Domain controllers to use for authentication, you may 
82 set this line to be :</para>
83
84 <para><command>password server = *</command></para>
85
86 <para>This method, allows Samba to use exactly the same
87 mechanism that NT does. This 
88 method either broadcasts or uses a WINS database in order to
89 find domain controllers to authenticate against.</para>
90
91 <para>In order to actually join the domain, you must run this
92 command:</para>
93
94 <para><prompt>root# </prompt><userinput>net join -S DOMPDC
95 -U<replaceable>Administrator%password</replaceable></userinput></para>
96
97 <para>
98 If the <userinput>-S DOMPDC</userinput> argument is not given then
99 the domain name will be obtained from smb.conf.
100 </para>
101
102 <para>as we are joining the domain DOM and the PDC for that domain 
103 (the only machine that has write access to the domain SAM database) 
104 is DOMPDC. The <replaceable>Administrator%password</replaceable> is 
105 the login name and password for an account which has the necessary 
106 privilege to add machines to the domain.  If this is successful 
107 you will see the message:</para>
108
109 <para><computeroutput>Joined domain DOM.</computeroutput>
110 or <computeroutput>Joined 'SERV1' to realm 'MYREALM'</computeroutput>
111 </para>
112
113 <para>in your terminal window. See the <ulink url="net.8.html">
114 net(8)</ulink> man page for more details.</para>
115
116 <para>This process joins the server to the domain
117 without having to create the machine trust account on the PDC
118 beforehand.</para>
119
120 <para>This command goes through the machine account password 
121 change protocol, then writes the new (random) machine account 
122 password for this Samba server into a file in the same directory 
123 in which an smbpasswd file would be stored - normally :</para>
124
125 <para><filename>/usr/local/samba/private/secrets.tdb</filename></para>
126
127 <para>This file is created and owned by root and is not 
128 readable by any other user. It is the key to the domain-level 
129 security for your system, and should be treated as carefully 
130 as a shadow password file.</para>
131
132 <para>Finally, restart your Samba daemons and get ready for 
133 clients to begin using domain security!</para>
134
135 <sect2>
136 <title>Why is this better than security = server?</title>
137
138 <para>Currently, domain security in Samba doesn't free you from 
139 having to create local Unix users to represent the users attaching 
140 to your server. This means that if domain user <constant>DOM\fred
141 </constant> attaches to your domain security Samba server, there needs 
142 to be a local Unix user fred to represent that user in the Unix 
143 filesystem. This is very similar to the older Samba security mode 
144 <ulink url="smb.conf.5.html#SECURITYEQUALSSERVER">security = server</ulink>, 
145 where Samba would pass through the authentication request to a Windows 
146 NT server in the same way as a Windows 95 or Windows 98 server would.
147 </para>
148
149 <para>Please refer to the <ulink url="winbind.html">Winbind 
150 paper</ulink> for information on a system to automatically
151 assign UNIX uids and gids to Windows NT Domain users and groups.
152 </para>
153
154 <para>The advantage to domain-level security is that the 
155 authentication in domain-level security is passed down the authenticated 
156 RPC channel in exactly the same way that an NT server would do it. This 
157 means Samba servers now participate in domain trust relationships in 
158 exactly the same way NT servers do (i.e., you can add Samba servers into 
159 a resource domain and have the authentication passed on from a resource
160 domain PDC to an account domain PDC).</para>
161
162 <para>In addition, with <command>security = server</command> every Samba 
163 daemon on a server has to keep a connection open to the 
164 authenticating server for as long as that daemon lasts. This can drain 
165 the connection resources on a Microsoft NT server and cause it to run 
166 out of available connections. With <command>security = domain</command>, 
167 however, the Samba daemons connect to the PDC/BDC only for as long 
168 as is necessary to authenticate the user, and then drop the connection, 
169 thus conserving PDC connection resources.</para>
170
171 <para>And finally, acting in the same manner as an NT server 
172 authenticating to a PDC means that as part of the authentication 
173 reply, the Samba server gets the user identification information such 
174 as the user SID, the list of NT groups the user belongs to, etc. </para>
175
176 <note><para> Much of the text of this document 
177 was first published in the Web magazine <ulink url="http://www.linuxworld.com">         
178 LinuxWorld</ulink> as the article <ulink
179 url="http://www.linuxworld.com/linuxworld/lw-1998-10/lw-10-samba.html">Doing 
180 the NIS/NT Samba</ulink>.</para></note>
181 </sect2>
182 </sect1>
183
184 <sect1>
185 <title>Machine Trust Accounts and Domain Membership</title>
186
187 <para>
188 A machine trust account is an account that is used to authenticate a client machine
189 (rather than a user) to the Domain Controller server.  In Windows terminology,
190 this is known as a "Computer Account."</para>
191
192 <para>
193 The password of a machine trust account acts as the shared secret for
194 secure communication with the Domain Controller.  This is a security
195 feature to prevent an unauthorized machine with the same NetBIOS name
196 from joining the domain and gaining access to domain user/group
197 accounts.  Windows NT, 200x, XP Professional clients use machine trust
198 accounts, but Windows 9x / Me / XP Home clients do not.  Hence, a
199 Windows 9x / Me / XP Home  client is never a true member of a domain
200 because it does not possess a machine trust account, and thus has no
201 shared secret with the domain controller.
202 </para>
203
204 <para>A Windows NT4 PDC stores each machine trust account in the Windows
205 Registry. The introduction of MS Windows 2000 saw the introduction of Active Directory,
206 the new repository for machine trust accounts.
207 </para>
208
209 <para>
210 A Samba PDC, however, stores each machine trust account in two parts,
211 as follows:
212
213 <itemizedlist>
214     <listitem><para>A Samba account, stored in the same location as user
215     LanMan and NT password hashes (currently <filename>smbpasswd</filename>).
216     The Samba account possesses and uses only the NT password hash.</para></listitem>
217
218     <listitem><para>A corresponding Unix account, typically stored in
219     <filename>/etc/passwd</filename>. (Future releases will alleviate the need to
220     create <filename>/etc/passwd</filename> entries.) </para></listitem>
221 </itemizedlist>
222 </para>
223
224 <para>
225 There are two ways to create machine trust accounts:
226 </para>
227
228 <itemizedlist>
229         <listitem><para> Manual creation. Both the Samba and corresponding
230         Unix account are created by hand.</para></listitem>
231         
232         <listitem><para> "On-the-fly" creation. The Samba machine trust
233         account is automatically created by Samba at the time the client
234         is joined to the domain. (For security, this is the
235         recommended method.) The corresponding Unix account may be
236         created automatically or manually. </para>
237         </listitem>
238
239 </itemizedlist>
240
241 <sect2>
242 <title>Manual Creation of Machine Trust Accounts</title>
243
244 <para>
245 The first step in manually creating a machine trust account is to
246 manually create the corresponding Unix account in
247 <filename>/etc/passwd</filename>.  This can be done using
248 <command>vipw</command> or other 'add user' command that is normally
249 used to create new Unix accounts.  The following is an example for a
250 Linux based Samba server:
251 </para>
252
253 <para>
254   <prompt>root# </prompt><command>/usr/sbin/useradd -g 100 -d /dev/null -c <replaceable>"machine 
255 nickname"</replaceable> -s /bin/false <replaceable>machine_name</replaceable>$ </command>
256 </para>
257 <para>
258 <prompt>root# </prompt><command>passwd -l <replaceable>machine_name</replaceable>$</command>
259 </para>
260
261 <para>On *BSD systems, this can be done using the 'chpass' utility:</para>
262
263 <para>
264 <prompt>root# </prompt><command>chpass -a "<replaceable>machine_name</replaceable>$:*:101:100::0:0:Workstation <replaceable>machine_name</replaceable>:/dev/null:/sbin/nologin"</command>
265 </para>
266
267 <para>
268 The <filename>/etc/passwd</filename> entry will list the machine name 
269 with a "$" appended, won't have a password, will have a null shell and no 
270 home directory. For example a machine named 'doppy' would have an 
271 <filename>/etc/passwd</filename> entry like this:
272 </para>
273
274 <para><programlisting>
275 doppy$:x:505:501:<replaceable>machine_nickname</replaceable>:/dev/null:/bin/false
276 </programlisting></para>
277
278 <para>
279 Above, <replaceable>machine_nickname</replaceable> can be any
280 descriptive name for the client, i.e., BasementComputer.
281 <replaceable>machine_name</replaceable> absolutely must be the NetBIOS
282 name of the client to be joined to the domain.  The "$" must be
283 appended to the NetBIOS name of the client or Samba will not recognize
284 this as a machine trust account.
285 </para>
286
287 <para>
288 Now that the corresponding Unix account has been created, the next step is to create 
289 the Samba account for the client containing the well-known initial 
290 machine trust account password.  This can be done using the <ulink 
291 url="smbpasswd.8.html"><command>smbpasswd(8)</command></ulink> command 
292 as shown here:
293 </para>
294
295 <para>
296 <prompt>root# </prompt><userinput>smbpasswd -a -m <replaceable>machine_name</replaceable></userinput>
297 </para>
298
299 <para>
300 where <replaceable>machine_name</replaceable> is the machine's NetBIOS
301 name.  The RID of the new machine account is generated from the UID of 
302 the corresponding Unix account.
303 </para>
304
305 <warning>
306         <title>Join the client to the domain immediately</title>
307
308         <para>
309         Manually creating a machine trust account using this method is the 
310         equivalent of creating a machine trust account on a Windows NT PDC using 
311         the "Server Manager".  From the time at which the account is created
312         to the time which the client joins the domain and changes the password,
313         your domain is vulnerable to an intruder joining your domain using
314         a machine with the same NetBIOS name.  A PDC inherently trusts
315         members of the domain and will serve out a large degree of user 
316         information to such clients.  You have been warned!
317         </para>
318 </warning>
319 </sect2>
320
321
322 <sect2>
323 <title>"On-the-Fly" Creation of Machine Trust Accounts</title>
324
325 <para>
326 The second (and recommended) way of creating machine trust accounts is
327 simply to allow the Samba server to create them as needed when the client
328 is joined to the domain. </para>
329
330 <para>Since each Samba machine trust account requires a corresponding
331 Unix account, a method for automatically creating the
332 Unix account is usually supplied; this requires configuration of the
333 <ulink url="smb.conf.5.html#ADDMACHINESCRIPT">add machine script</ulink> 
334 option in <filename>smb.conf</filename>.  This
335 method is not required, however; corresponding Unix accounts may also
336 be created manually.
337 </para>
338
339
340 <para>
341 Below is an example for a RedHat Linux system.
342 </para>
343
344 <para><programlisting>
345 [global]
346    # &lt;...remainder of parameters...&gt;
347    add machine script = /usr/sbin/useradd -d /dev/null -g 100 -s /bin/false -M %u 
348 </programlisting></para>
349
350 </sect2>
351
352
353 <sect2><title>Joining the Client to the Domain</title>
354
355 <para>
356 The procedure for joining a client to the domain varies with the version of Windows.
357 </para>
358
359 <itemizedlist>
360 <listitem><para><emphasis>Windows 2000</emphasis></para>
361
362         <para>
363         When the user elects to join the client to a domain, Windows prompts for
364         an account and password that is privileged to join the domain. A Samba administrative
365         account (i.e., a Samba account that has root privileges on the Samba server) must be
366         entered here; the operation will fail if an ordinary user account is given. 
367         The password for this account should be set to a different password than the associated
368         <filename>/etc/passwd</filename> entry, for security reasons.
369         </para>
370
371         <para>
372         The session key of the Samba administrative account acts as an
373         encryption key for setting the password of the machine trust
374         account. The machine trust account will be created on-the-fly, or
375         updated if it already exists.
376         </para>
377
378 </listitem>
379
380 <listitem><para><emphasis>Windows NT</emphasis></para>
381
382     <para> If the machine trust account was created manually, on the
383         Identification Changes menu enter the domain name, but do not
384         check the box "Create a Computer Account in the Domain."  In this case,
385         the existing machine trust account is used to join the machine to
386         the domain.</para>
387
388     <para> If the machine trust account is to be created
389         on-the-fly, on the Identification Changes menu enter the domain
390         name, and check the box "Create a Computer Account in the Domain."  In
391         this case, joining the domain proceeds as above for Windows 2000
392         (i.e., you must supply a Samba administrative account when
393         prompted).</para>
394 </listitem>
395
396 <listitem><para><emphasis>Samba</emphasis></para>
397         <para>Joining a samba client to a domain is documented in 
398         the <link linkend="domain-member">Domain Member</link> chapter.
399 </para></listitem>
400 </itemizedlist>
401
402 </sect2>
403 </sect1>
404
405 <sect1>
406 <title>Samba ADS Domain Membership</title>
407
408 <para>
409 This is a rough guide to setting up Samba 3.0 with kerberos authentication against a
410 Windows2000 KDC. 
411 </para> 
412
413 <sect2>
414 <title>Setup your <filename>smb.conf</filename></title>
415
416 <para>You must use at least the following 3 options in smb.conf:</para>
417
418 <para><programlisting>
419         realm = your.kerberos.REALM
420         security = ADS
421         encrypt passwords = yes
422 </programlisting></para>
423
424 <para>
425 In case samba can't figure out your ads server using your realm name, use the 
426 <command>ads server</command> option in <filename>smb.conf</filename>:
427 <programlisting>
428         ads server = your.kerberos.server
429 </programlisting>
430 </para>
431
432 <note><para>You do *not* need a smbpasswd file, and older clients will
433   be authenticated as if <command>security = domain</command>,
434   although it won't do any harm
435   and allows you to have local users not in the domain.
436   I expect that the above required options will change soon when we get better
437   active directory integration.</para></note>
438
439 </sect2>
440   
441 <sect2>
442 <title>Setup your <filename>/etc/krb5.conf</filename></title>
443
444 <para>Note: you will need the krb5 workstation, devel, and libs installed</para>
445
446 <para>The minimal configuration for <filename>krb5.conf</filename> is:</para>
447
448 <para><programlisting>
449         [realms]
450             YOUR.KERBEROS.REALM = {
451                 kdc = your.kerberos.server
452             }
453 </programlisting></para>
454
455 <para>Test your config by doing a <userinput>kinit
456 <replaceable>USERNAME</replaceable>@<replaceable>REALM</replaceable></userinput> and
457 making sure that your password is accepted by the Win2000 KDC.
458 </para>
459
460 <note><para>The realm must be uppercase or you will get "Cannot find KDC for requested
461 realm while getting initial credentials" error </para></note>
462
463 <note><para>Time between the two servers must be synchronized.  You will get a
464 "kinit(v5): Clock skew too great while getting initial credentials" if the time
465 difference is more than five minutes. </para></note>
466
467 <para>
468 You also must ensure that you can do a reverse DNS lookup on the IP
469 address of your KDC. Also, the name that this reverse lookup maps to
470 must either be the netbios name of the KDC (ie. the hostname with no
471 domain attached) or it can alternatively be the netbios name
472 followed by the realm. 
473 </para>
474
475 <para>
476 The easiest way to ensure you get this right is to add a 
477 <filename>/etc/hosts</filename> entry mapping the IP address of your KDC to 
478 its netbios name. If you don't get this right then you will get a 
479 "local error" when you try to join the realm.
480 </para>
481
482 <para>
483 If all you want is kerberos support in &smbclient; then you can skip
484 straight to <link linkend="ads-test-smbclient">Test with &smbclient;</link> now. 
485 <link linkend="ads-create-machine-account">Creating a computer account</link> 
486 and <link linkend="ads-test-server">testing your servers</link>
487 is only needed if you want kerberos support for &smbd; and &winbindd;.
488 </para>
489
490 </sect2>
491
492 <sect2 id="ads-create-machine-account">
493 <title>Create the computer account</title>
494
495 <para>
496 As a user that has write permission on the Samba private directory
497 (usually root) run:
498 <programlisting>
499         <userinput>net join -U Administrator%password</userinput>
500 </programlisting>
501 </para>
502
503 <sect3>
504 <title>Possible errors</title>
505
506 <para>
507 <variablelist>
508         <varlistentry><term>"ADS support not compiled in"</term>
509         <listitem><para>Samba must be reconfigured (remove config.cache) and recompiled
510         (make clean all install) after the kerberos libs and headers are installed.
511         </para></listitem></varlistentry>
512
513         <varlistentry><term>net join prompts for user name</term>
514         <listitem><para>You need to login to the domain using <userinput>kinit
515         <replaceable>USERNAME</replaceable>@<replaceable>REALM</replaceable></userinput>.
516         <replaceable>USERNAME</replaceable> must be a user who has rights to add a machine
517         to the domain.  </para></listitem></varlistentry>
518 </variablelist>
519 </para>
520
521 </sect3>
522
523 </sect2>
524
525 <sect2 id="ads-test-server">
526 <title>Test your server setup</title>
527
528 <para>
529 If the join was successful, you will see a new computer account with the
530 NetBIOS name of your Samba server in Active Directory (in the "Computers"
531 folder under Users and Computers.
532 </para>
533
534 <para>
535 On a Windows 2000 client try <userinput>net use * \\server\share</userinput>. You should
536 be logged in with kerberos without needing to know a password. If
537 this fails then run <userinput>klist tickets</userinput>. Did you get a ticket for the
538 server? Does it have an encoding type of DES-CBC-MD5 ? 
539 </para>
540
541 </sect2>
542
543 <sect2 id="ads-test-smbclient">
544 <title>Testing with &smbclient;</title>
545
546 <para>
547 On your Samba server try to login to a Win2000 server or your Samba
548 server using &smbclient; and kerberos. Use &smbclient; as usual, but
549 specify the <parameter>-k</parameter> option to choose kerberos authentication.
550 </para>
551
552 </sect2>
553
554 <sect2>
555 <title>Notes</title>
556
557 <para>You must change administrator password at least once after DC 
558 install, to create the right encoding types</para>
559
560 <para>w2k doesn't seem to create the _kerberos._udp and _ldap._tcp in
561    their defaults DNS setup. Maybe fixed in service packs?</para>
562 </sect2>
563
564 </sect1>
565 </chapter>