Project

General

Profile

Linux Domain join howto » History » Version 1

Viacheslav Anzhiganov, 02/05/2025 07:20 AM

1 1 Viacheslav Anzhiganov
# Linux Domain join howto
2
3
Origin: https://blog.svedr.in/posts/linux-domain-join-howto/
4
5
6
There are quite a few tutorials on how to join a Linux machine into a Windows Domain. Some of them are outdated and talk about old-style domains instead of Active Directory. Others require the Active Directory schema be extended. Most of them neglect configuring the system so that Kerberos can be used correctly. And almost none of 'em show how to configure stable user IDs that are reproducible across multiple systems, so using NFS and DRBD will actually work instead of completely breaking permissions.
7
8
So, here's my own howto which fixes all of this. It lays out the config I use in my home samba4 domain, LOCAL.LAN. (Yes, I do have an Active Directory domain at home. I like it, even. This is how crazy I am.)
9
10
1. You'll want to make sure that your hostname (the one that the hostname command spits out) is not longer than 15 characters and does not consist of numbers only. (I once named a host 1319. This seemed to work at first but caused some very strange behaviour later on. Renaming the host 13-19 fixed that.)
11
2. Make sure that hostname --fqdn actually spits out an FQDN and not just the hostname. Vice versa, make sure that hostname without --fqdn does not spit out an FQDN.
12
13
You can do this by adjusting */etc/hostname* and */etc/hosts* . Make sure */etc/hosts* contains a line such as this one for the hostname you set in */etc/hostname* :
14
15
```
16
# IP            FQDN               Hostname
17
127.0.1.1       hive.local.lan     hive
18
```
19
20
Put the FQDN first, and the short hostname second. Do not omit either one. Do not put the FQDN in /etc/hostname.
21
22
Install the samba daemons, winbind and the Kerberos utilities:
23
24
```
25
apt-get install samba winbind libnss-winbind krb5-user
26
```
27
28
4. Put the following into /etc/krb5.conf, replacing LOCAL.LAN with your domain name:
29
30
```
31
[libdefaults]
32
   default_realm = LOCAL.LAN
33
   default_keytab_name = /etc/krb5.keytab
34
   default_tkt_enctypes = rc4-hmac des-cbc-crc des-cbc-md5
35
   default_tgs_enctypes = rc4-hmac des-cbc-crc des-cbc-md5
36
37
[domain_realm]
38
   .local.lan = LOCAL.LAN
39
   local.lan = LOCAL.LAN
40
```
41
42
Note that capitalization matters.
43
44
5. Put this into /etc/samba/smb.conf, again adapting the netbios name, workgroup and realm to your environment:
45
46
```
47
[global]
48
   netbios name = HIVE
49
   workgroup    = LOCALLAN
50
   realm        = LOCAL.LAN
51
   security     = ADS
52
53
   encrypt passwords = yes
54
55
   # Load the acl_xattr module for Windows ACL support
56
   vfs objects = shadow_copy2 acl_xattr
57
58
   # Use an external keytab that can be used for other services (e.g. apache)
59
   kerberos method = dedicated keytab
60
   dedicated keytab file = /etc/krb5.keytab
61
62
   idmap config *:backend = tdb
63
   idmap config *:range   = 1000000-1999999
64
65
   # Make sure we have reproducible user IDs
66
   idmap config LOCALLAN:backend = rid
67
   idmap config LOCALLAN:range   = 10000-999999
68
69
   winbind nss info = rfc2307
70
   winbind trusted domains only = no
71
   winbind use default domain = yes
72
73
   # should "getent passwd" and "getent group" list *all* AD users/groups?
74
   winbind enum users  = yes
75
   winbind enum groups = yes
76
77
   # Default shell that users get (/bin/true = no login)
78
   template shell = /bin/true
79
```
80
81
6. Just in case, rm -f /etc/krb5.keytab. It shouldn't be there, but now it definitely won't be.
82
83
7. Authenticate as an administrator:
84
85
```
86
kinit Administrator
87
```
88
89
You will be prompted for your password. (See how to get rid of passwords)
90
91
Once that worked, proceed to actually joining the domain:
92
93
```
94
net ads -k join
95
net ads -k keytab create
96
```
97
98
If you want to provide authentication for other services via Kerberos, add the service principal names for those services to your newly-created machine account:
99
100
```
101
net ads -k keytab add HTTP
102
net ads -k keytab add HTTPS
103
net ads -k keytab add NFS
104
```
105
I'm not sure if you need one for SSH too, or if SSH just uses the default HOST principal, but you might as well add it just-in-case. By the way, this command also updates the machine account on the AD side, so no adsiedit and copying around keytab files necessary.
106
107
Now you won't need the Kerberos ticket anymore:
108
109
```
110
kdestroy
111
```
112
Let's see if the domain account is set up correctly and Kerberos authentication works. We do this by acquiring a Kerberos ticket for the machine account:
113
114
```
115
kinit -k HOSTNAME$
116
```
117
That $ sign at the end of the HOSTNAME is part of the command, so for hive, I'd have to run kinit -k HIVE$. HIVE$ is the name of the computer account created for the machine named HIVE, for which we want to get a ticket.
118
119
Note that you may need to retry this command a few times until ADS set up everything. It should work after a couple of seconds though.
120
121
Restart the samba services:
122
123
```
124
service smbd restart
125
service nmbd restart
126
service winbind restart
127
```
128
For users and groups to be resolvable in the system (e.g. for ls and friends), modify /etc/nsswitch.conf:
129
130
```
131
passwd: compat winbind
132
group:  compat winbind
133
```
134
135
Verify using:
136
137
```
138
# getent passwd Administrator
139
administrator:*:10500:10513:Administrator:/home/LOCALLAN/administrator:/bin/true
140
# getent group "Domain Admins"
141
domain admins:x:10512:svedrin,administrator
142
```
143
144
Both commands should spit out something.
145
146
Congrats, you've joined an Active Directory domain!
147
148
Update: This guy appears to have been as frustrated with this stuff as I have, and he has some nice tips about what to do when the getent something parts fail.