如何使用ubuntu上使用samba设置Linux域控制器

时间:2020-03-05 15:32:48  来源:igfitidea点击:

Samba是SMB文件共享协议的开源实现,为SMB/CIFS客户端提供文件和打印服务。
它有助于使用Windows客户端成功向Ubuntu系统组网,从而提供和集成Windows环境共有的服务。
这些服务协助分享数据和有关网络中涉及的计算机和用户的信息,并且可以在功能方面按三个主要类别分类

文件和打印机共享服务:它使用服务器消息块(SMB)协议来促进整个网络中的文件,文件夹,卷和打印机的共享。

目录服务:在轻量级目录访问协议(LDAP)和Microsoft Active Directory的帮助下,它有关网络计算机和用户的重要信息。

身份验证和访问:它建立了网络或者网络的用户的标识,并确定计算机或者用户授权使用文件权限,组策略和Kerberos身份验证服务访问的信息。

在本教程中,我们了解如何在Ubuntu 16.04上使用Samba配置Linux域控制器。

Samba作为ADDC至少需要版本4.0.0。
我强烈建议使用最新的稳定版本的Samba,因为它将包含以前版本的错误和许多改进的Microsoft Active Directory兼容性和其他功能。

使用这一点的主要优点是,我们不需要安装单独的Kerberos KDC。
Samba包括AD兼容的KDC及其船舶,可为AD背面实现其自行的LDAP实现。

准备工作

  • 确保服务器配置为使用静态IP地址。如果地址更改,DHCP可能会导致故障。
  • 使用正确的名称服务器更新rollv.conf。
  • 使用正确的条目更新我们/etc/hosts文件。主机名应解析为服务器IP。

让我们从准备工作开始。
我会告诉你,如何修改我的服务器设置以满足我们的预先条件。

1)我们需要为静态IP配置网络接口。
使用服务器IP"96.126.107.141"编辑/etc/network/interfaces文件,域控制器名称"nodenixbox.com"等详细信息如下:

root@ubuntu:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 96.126.107.141
netmask 255.255.255.0
network 96.126.107.0
broadcast 96.126.107.255
gateway 96.126.107.1
dns-nameservers 96.126.107.141 8.8.8.8
dns-search nodenixbox.com
# This is an autoconfigured IPv6 interface
iface eth0 inet6 auto

我将iface eth0 inet dhcp更改为iface eth0 inet静态并将这些突出显示的部分添加到我的网络配置中。

2)编辑rolorv.conf文件以添加域控制器名称。

root@ubuntu:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 96.126.107.141
nameserver 8.8.8.8
nameserver 207.192.69.4
search nodenixbox.com

3)最后但不可最终编辑我们/etc/hosts文件并将"ubuntu.nodenixbox.com"设置为主机名,如下所示:

root@ubuntu:~# cat /etc/hosts
127.0.0.1 localhost
#127.0.1.1 ubuntu.members.linode.com ubuntu
96.126.107.141 ubuntu.nodenixbox.com ubuntu
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
root@ubuntu:~# echo ubuntu.nodenixbox.com > /etc/hostname
root@ubuntu:~# /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.

在这些修改后重新启动网络。

因此,我们已准备好开始安装包。

包装安装

首先,我们需要安装所有必需的软件包以设置我们的域控制器Active Directory。
我运行此命令以更新所有Server软件包并安装所需的软件。

root@ubuntu:~# apt-get update && apt-get upgrade -y
root@ubuntu:~# apt-get install git attr build-essential libacl1-dev libattr1-dev libblkid-dev libgnutls-dev libreadline-dev python-dev libpam0g-dev python-dnspython gdb pkg-config libpopt-dev libldap2-dev dnsutils libbsd-dev attr krb5-user docbook-xsl libcups2-dev acl ntp ntpdate winbind

在这些包装期间,我们将被要求提供Kerberos信息。
我们需要提供Kerberos默认域和管理员服务器信息。
我们可以输入默认域和NodenixBox.com和管理员服务器名称作为主机名。

如何安装和配置Samba

我们需要使用Git存储库下载最新的Samba软件包到"Samba4"文件夹中。

root@ubuntu:~# git clone -b v4-1-stable git://git.samba.org/samba.git samba4
Cloning into 'samba4'...
remote: Counting objects: 1276826, done.
remote: Compressing objects: 100% (280630/280630), done.
remote: Total 1276826 (delta 992350), reused 1267276 (delta 984263)
Receiving objects: 100% (1276826/1276826), 249.03 MiB | 10.51 MiB/s, done.
Resolving deltas: 100% (992350/992350), done.
Checking connectivity... done.

下载后,我们可以进入"Samba4"文件夹并配置Samba包。

root@ubuntu:~#cd samba4
root@ubuntu:~#./configure --enable-debug --enable-selftest
root@ubuntu:~#make
root@ubuntu:~/samba4# make
WAF_MAKE=1 python ./buildtools/bin/waf build
Waf: Entering directory `/root/samba4/bin'
Selected embedded Heimdal build
Waf: Leaving directory `/root/samba4/bin'
'build' finished successfully (6.288s)
root@ubuntu:~#make install

Samba编译可能需要一段时间才能完成。
一旦完成,用Samba和SMB客户端版本确认。
这两个版本都应该匹配。

root@ubuntu:~# /usr/local/samba/sbin/samba -V
Version 4.1.23
root@ubuntu:~# /usr/local/samba/bin/smbclient -V
Version 4.1.23

配置Samba Active Directory

下一步是提供域名。
我们可以简单运行此命令以提供域。

root@ubuntu:~/samba4# /usr/local/samba/bin/samba-tool domain provision --realm=nodenixbox.com --domain=nodenixbox --adminpass="password" --server-role=dc --dns-backend=SAMBA_INTERNAL
Looking up IPv4 addresses
Looking up IPv6 addresses
Setting up secrets.ldb
Setting up the registry
Setting up the privileges database
Setting up idmap db
Setting up SAM db
Setting up sam.ldb partitions and settings
Setting up sam.ldb rootDSE
Pre-loading the Samba 4 and AD schema
Adding DomainDN: DC=nodenixbox,DC=com
Adding configuration container
Setting up sam.ldb schema
Setting up sam.ldb configuration data
Setting up display specifiers
Modifying display specifiers
Adding users container
Modifying users container
Adding computers container
Modifying computers container
Setting up sam.ldb data
Setting up well known security principals
Setting up sam.ldb users and groups
Setting up self join
Adding DNS accounts
Creating CN=MicrosoftDNS,CN=System,DC=nodenixbox,DC=com
Creating DomainDnsZones and ForestDnsZones partitions
Populating DomainDnsZones and ForestDnsZones partitions
Setting up sam.ldb rootDSE marking as synchronized
Fixing provision GUIDs
A Kerberos configuration suitable for Samba 4 has been generated at /usr/local/samba/private/krb5.conf
Once the above files are installed, your Samba4 server will be ready to use
Server Role: active directory domain controller
Hostname: ubuntu
NetBIOS Domain: NODENIXBOX
DNS Domain: nodenixbox.com
DOMAIN SID: S-1-5-21-4019752003-3807572232-1148719748

一些使用Bind9作为后端DNS,但Samba包含自己的全功能DNS服务器。
其中我正在使用samba_internal。
设置此域后,我们需要启动Samba服务。
我们可以运行此命令以启动Samba。

root@ubuntu:~# /usr/local/samba/sbin/samba
root@ubuntu:~#

测试SAMBA域控制器

我们可以运行"smbclient",检查Samba是否提供了在配置期间在"SMB.conf"中创建的"NetLogon"和"sysvol"的AD DC默认共享。

root@ubuntu:~# /usr/local/samba/bin/smbclient -L localhost -U%
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.3.11-Ubuntu]
Sharename Type Comment
--------- ---- ------
print$Disk Printer Drivers
IPC$IPC IPC Service (ubuntu server (Samba, Ubuntu))
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.3.11-Ubuntu]
Server Comment
--------- ------
UBUNTU ubuntu server (Samba, Ubuntu)
Workgroup Master
--------- ------
WORKGROUP UBUNTU

要测试身份验证是否正常工作,我们应该尝试使用在配置期间创建的域管理员帐户连接到"netlogon"共享。

root@ubuntu:~/samba4# /usr/local/samba/bin/smbclient //localhost/netlogon -UAdministrator -c 'ls'
Enter Administrator's password:
Domain=[NODENIXBOX] OS=[Unix] Server=[Samba 4.1.23]
. D 0 Sun Oct 16 09:30:02 2015
.. D 0 Sun Oct 16 09:31:09 2015
47431 blocks of size 524288. 40274 blocks available

配置Samba_Internal DNS.

工作DNS对于Active Directory的正确操作至关重要。
如果没有正确的DNS条目,Kerberos将无法正常工作,这反过来意味着许多基本功能将无法正常工作。
始终值得花费一些另外的时间,确保DNS设置以确保它正确完成。

我们需要使用我们的域名编辑我们的/etc/resolv.conf,如下所示:

root@ubuntu:~#echo domain nodenixbox.com >> /etc/resolv.conf

域控制器需要一个能够解析到Active Directory区域的查询的名称服务器。
因为这是我们在AD林中的第一域控制器。

我们还需要编辑Samba配置文件"/usr/local/samba/etc/smb.conf"并将Google名称服务器添加到DNS_Forwarder。

root@ubuntu:~# cat /usr/local/samba/etc/smb.conf
# Global parameters
[global]
workgroup = NODENIXBOX
realm = NODENIXBOX.COM
netbios name = UBUNTU
server role = active directory domain controller
dns forwarder = 8.8.8.8

测试DNS

要确认DNS,正常工作,请运行以下命令并比较输出

root@ubuntu:~# host -t SRV _ldap._tcp.nodenixbox.com
_ldap._tcp.nodenixbox.com has SRV record 0 100 389 ubuntu.nodenixbox.com
root@ubuntu:~# host -t SRV _kerberos._udp.nodenixbox.com.
_kerberos._udp.nodenixbox.com has SRV record 0 100 88 ubuntu.nodenixbox.com.
root@ubuntu:~# host -t A ubuntu.nodenixbox.com
ubuntu.nodenixbox.com has address 96.126.107.141

配置Kerberos.

Kerberos是Active Directory的重要组成部分。
通常,配置在/etc/krb5.conf中完成。
在配置过程中,将在/usr/local/samba/share/setup/krb5.conf中创建工作示例配置。
我们可以通过复制或者创建Symlink将KRB5.conf文件替换为示例。

root@ubuntu:~# ln -s /usr/local/samba/share/setup/krb5.conf /etc/krb5.conf

我们需要编辑此文件并将Default_realm与DC名称修改如下:

root@ubuntu:~# cat //etc/krb5.conf
[libdefaults]
default_realm = NODENIXBOX.COM
dns_lookup_realm = false
dns_lookup_kdc = true

领域名称应该是大写的。

测试Kerberos.

我们可以使用KINIT来测试Kerberos配置。
运行此命令如下用于测试:

root@ubuntu:~# kinit [email protected]
Password for [email protected]:
Warning: Your password will expire in 41 days on Sun 27 Nov 2015 09:31:07 AM UTC

我们需要通过运行此命令禁用Active Directory管理员用户的密码到期,以避免未来的身份验证问题。

root@ubuntu:~# /usr/local/samba/bin/samba-tool user setexpiry administrator --noexpiry
Expiry for user 'administrator' disabled.

注意:我们必须始终以大写字母指定领域。
要验证Kerberos工作,我们可以运行此功能。

root@ubuntu:~# klist -e
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]
Valid starting Expires Service principal
10/17/2015 04:19:31 10/17/2015 14:19:31 krbtgt/[email protected]
renew until 10/18/2015 04:19:19, Etype (skey, tkt): arcfour-hmac, arcfour-hmac

创建用户主文件夹

现在,我们可以创建用户主页文件夹并设置适当的权限和所有权。

root@ubuntu:~# mkdir -m 770 /Users
root@ubuntu:~# chmod g+s /Users
root@ubuntu:~# chown root:users /Users

接下来,我们需要编辑SMB配置文件"/usr/local/samba/etc/smb.conf"如下所示:

[Users]
directory_mode: parameter = 0700
read only = no
path = /Users
csc policy = documents

配置NTP.

Active Directory需要在Kerberos的所有参与者计算机之间进行关闭时间同步正常工作。
强烈建议在域控制器上使用NTP进行时间同步。
此目录将为我们提供所有必要的信息,在AD域控制器上配置NTP。