Como criar um Active Directory usando o Debian, com pacotes samba 4, LDAP e Kerberos.

O SAMBA, na versão 4, implementa um serviço de diretórios LDAP, com autenticação Kerberos, oferece suporta a DNS dinâmico e atende muitos serviços para os quais, antes, só se pensava no Active Directory.

Hoje ele fornece tudo necessário para trabalhar como um Active Directory Domain Controler, tendo compatibilidade total com o Sistema Operacional Microsoft Windows atual. Sendo que podemos implementá-lo em ambientes de produção como Controlador de Domínio primário ou secundário, ao nível funcional de floresta compatível com Windows Server 2008 R2 ou superior..

Instalando pacotes essenciais no Debian para o Controlador de Domínio, Samba 4

INSTALAÇÃO DOS PACOTES:
apt-get update
apt-get install linux-source linux-headers-$(uname -r) build-essential ssh vim ntp ntpdate samba winbind libnss-winbind acl attr ldb-tools
BACKUP/CONFIGURAÇÃO DO ARQUIVO DE SINCRONISMO DE TEMPO:
cp /etc/ntp.conf /etc/ntp.conf.orig

CONFIGURAÇÃO DO ARQUIVO DO TIME:

vim /etc/ntp.conf
 driftfile /var/lib/ntp/ntp.drift
 statsdir /var/log/ntpstats/
 restrict default nomodify notrap noquery
 restrict 127.0.0.1
 restrict 192.168.0.254 mask 255.255.255.0 nomodify notrap
 server a.st1.ntp.br
 server b.st1.ntp.br
 server c.st1.ntp.br
 server d.st1.ntp.br
 server a.ntp.br
 server b.ntp.br
 server c.ntp.br
 server gps.ntp.br

SINCRONIZANDO TEMPO:

ntpdate -u a.ntp.br

SETANDO PERMISSÕES DO AD:
(altere de acordo com seu particionamento)

tune2fs -o acl,user_xattr /dev/sda2
vim /etc/fstab
/dev/sda2 /home ext4 user_xattr,acl,barrier=1 1 1
mount -o remount,rw /home

TESTE DE PERMISSÕES DO AD:

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

RETORNO DOS COMANDOS:

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

SETANDO HOSTNAME:

vim /etc/hostname
ad
hostname ad
hostname -f

SETANDO RESOLVEDORES:

vim /etc/resolv.conf
domain eshark.info
search eshark.info.
nameserver 192.168.0.250    #PRÓPRIO AD
nameserver 192.168.0.254    #Firewall

SETANDO IP:

vim /etc/network/interfaces
iface eth0 inet static
address 192.168.0.250
netmask 255.255.255.0
gateway 192.168.0.254
dns-nameservers 192.168.0.250 192.168.0.254
dns-search eshark.info

SUBINDO CONFIGURAÇÕES DA PLACA DE REDE:

ifup eth0

SETANDO HOSTS:

vim /etc/hosts
.0.0.1              localhost
127.0.1.1           localhost.localdomain
192.168.0.250       ad.eshark.info ad
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

BACKUP DO smb.conf ORIGINAL ANTES DE PROVISIONAR:

mv /etc/samba/smb.conf /etc/samba/smb.conf.orig

PROVISIONAMENTO:

samba-tool domain provision --interactive --use-rfc2307 --option="interfaces=lo eth0" --option="bind interfaces only=yes"

(Quando solicitar dns-forwarder aponte para o firewall)
COPIANDO O krb5.conf PARA O DIRETÓRIO /etc:

cp /var/lib/samba/private/krb5.conf /etc

OU USE UM EXEMPLO PARA /etc/krb5.conf:

default_realm = .eshark.info
dns_lookup_realm = false
dns_lookup_kdc = true
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true

[realms]

.eshark.info = { kdc = ad.eshark.info admin_server = ad.eshark.info }

[domain_realm]

.eshark.info = .eshark.info eshark.info = eshark.info

SE OPTAR POR PERFIL MÓVEL:

mkdir /var/lib/samba/profiles
chmod -R 775 /var/lib/samba/profiles
chown -R root:users /var/lib/samba/profiles

APONTANDO O CAMINHO NO smb.conf:
(seção global abaixo de sysvol)

vim /etc/samba/smb.conf
[profiles]
      path = /var/lib/samba/profiles
      comment = Perfil Movel
      read only = No

Ao optar por Perfil móvel crie a pasta em /etc/samba/var/profiles, aponte no arquivo /etc/samba/smb.conf e sete no perfil de usuário do AD através das ferramentas do RSAT, lá no Windows, seguindo o caminho:
Usuário > Propriedades de usuário > Perfil > Caminho do perfil

\\ad\profiles\%USERNAME%

AUDITORIA NO AD:
(seção global abaixo de profiles:)

vim /etc/samba/smb.conf
# AUDITORIA
       vfs objects = full_audit
       full_audit:sucess = open, opendir, write, rename, mkdir, rmdir, chmod, chown
       full_audit:prefix = %U|%I|%S
       full_audit:failure = none
       full_audit:facility = local5
       full_audit:priority = notice

TESTES DE AUDITORIA EM TEMPO REAL:

smbcontrol all reload-config
tail -f /var/log/syslog | grep -E “open|unlink|rename”
cat /var/log/syslog | grep unlink

CRIANDO/SETANDO PERMISSÕES DA LIXEIRA:

mkdir /home/lixeira
chown root:users /home/lixeira
chmod 775 /home/lixeira -R

APONTANDO O CAMINHO NO AD:
(seção global abaixo de auditoria:)

vim /etc/samba/smb.conf
# LIXEIRA
      vfs objects = recycle
      recycle:keeptree = yes
      recycle:versions = yes
      recycle:repository = /home/lixeira/%U
      recycle:exclude = *.tmp, *.log, *.obj, ~*.*, *.bak, *.iso
      recycle:exclude_dir = tmp, cache

CRIANDO O DIRETÓRIO DE COMPARTILHAMENTOS:
(Lembre-se de criar os seus próprios diretórios, como ex: DIRETORIA, RH, TECNICOS, etc)

mkdir /home/DADOS
chmod 775 /home/DADOS/ -R
chown root:users /home/DADOS/ -R

APONTANDO O CAMINHO NO smb.conf (seção global abaixo da lixeira):

vim /etc/samba/smb.conf
[DADOS]
      path = /home/DADOS
      comment = Compartilhamentos da Rede
      read only = No

EXEMPLO DE smb.conf:

 # Global parameters
 

[global]

bind interfaces only = Yes interfaces = lo eth0 netbios name = AD realm = ESHARK.INFO workgroup = ESHARK dns forwarder = 192.168.0.254  #FIREWALL server role = active directory domain controller server services = s3fs rpc nbt wrepl ldap cldap kcd drepl winbind ntp_signd kcc dnsupdate dns

[netlogon]

path = /var/lib/samba/sysvol/eshark.info/scripts read only = No

[sysvol]

path = /var/lib/samba/sysvol read only = No

[profiles]

path = /var/lib/samba/profiles read only = No # AUDITORIA vfs objects = full_audit full_audit:sucess = open, opendir, write, rename, mkdir, rmdir, chmod, chown full_audit:prefix = %U|%I|%S full_audit:failure = none full_audit:facility = local5 full_audit:priority = notice # LIXEIRA vfs objects = recycle recycle:keeptree = yes recycle:versions = yes recycle:repository = /home/lixeira/%U recycle:exclude = *.tmp, *.log, *.obj, ~*.*, *.bak, *.iso recycle:exclude_dir = tmp, cache # COMPARTILHAMENTOS [DADOS] path = /home/DADOS comment = COMPARTILHAMENTOS read only = No

RESTARTANDO SERVIÇO DO SAMBA 4:

/etc/init.d/samba restart

VERIFICANDO SERVIÇO ATIVO:

ps aux | grep samba
testparm

DESABILITANDO COMPLEXIDADES DE SENHAS (OPCIONAL):

samba-tool domain passwordsettings show
samba-tool domain passwordsettings set --complexity=off --history-length=0 --min-pwd-length=0 --min-pwd-age=0

INSTALANDO PACOTE PARA AUTENTICAÇÃO NO KERBEROS:
(Use configurações default e aponte o ip 127.0.0.1 quando solicitado)

apt-get install krb5-user

RELENDO CONFIGURAÇÕES DO SAMBA 4:

smbcontrol all reload-config

REVISANDO USUÁRIOS:

samba-tool user list
samba-tool group list

TESTANDO TROCA DE TIKETs:

kinit Administrator@ESHARK.INFO
klist

TESTANDO DOMÍNIO COM dig:

dig eshark.info

CONSULTANDO kerberos e ldap:

host -t srv _kerberos._tcp.eshark.info
host -t srv _ldap._tcp.eshark.inf

O restante das configurações poderão ser feitas agora no AD, através das Ferramentas de administração do Windows Server 2008 R2 (RSAT), instaladas em uma versão de Windows 7, 8 ou 10.
Você pode gostar de ver este ambiente rodando em FreeBSD, para isso clique no botão abaixo:

Controlador de Domínio com FreeBSD

Este é o meu modo de fazer a coisa neste momento, continuo estudando e aberto!
That’s all folks!

Share This Article
Follow:
Fundador do SempreUPdate. Acredita no poder do trabalho colaborativo, no GNU/Linux, Software livre e código aberto. É possível tornar tudo mais simples quando trabalhamos juntos, e tudo mais difícil quando nos separamos.
Sair da versão mobile