Samba Tutorial · 7 min read · Dec 14, 2025
Samba 4 con Active Directory su installazione basata su rpm di CentOS 7 con supporto per condivisioni
Nell’ultimo tutorial, ti ho mostrato come configurare Samba su Centos 7 compilando Samba da sorgente poiché il pacchetto fornito da RedHat non supporta Active Directory. Ho notato che c’è un repository chiamato Wing che fornisce il pacchetto samba4 rpm con supporto AD. In questo tutorial, utilizzerò questo repository per l’installazione di Samba. Mostrerò anche come creare una condivisione samba.
In questo tutorial, utilizzerò un server CentOS 7 con un’installazione minima come base con SELinux abilitato.
Preparare il server CentOS 7
Controlla lo stato di SELinux.
[root@samba4 ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
[root@samba4 ~]#
Fai un’entrata nel file host con l’indirizzo IP del server seguito dal nome host completo (fqdn) e poi dalla parte locale del nome host.
[root@samba4 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.190 samba4.sunil.cc samba4
[root@samba4 ~]#
Installa il repository Epel di CentOS.
[root@samba4 ~]# yum install epel-release -yInstalla i pacchetti di base.
[root@samba4 ~]# yum install vim wget authconfig krb5-workstation -y
Ora installa il repository wing.
[root@samba4 ~]# cd /etc/yum.repos.d/
[root@samba4 yum.repos.d]# wget http://wing-net.ddo.jp/wing/7/EL7.wing.repo
[root@samba4 yum.repos.d]# sed -i 's@enabled=0@enabled=1@g' /etc/yum.repos.d/EL7.wing.repo
[root@samba4 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates wing wing-source
Cleaning up everything
Cleaning up list of fastest mirrors
[root@samba4 yum.repos.d]#
Installare Samba 4 su CentOS 7
Installazione dei pacchetti Samba4 dal repository wing con yum.
[root@samba4 yum.repos.d]# yum install -y samba45 samba45-winbind-clients samba45-winbind samba45-client\
samba45-dc samba45-pidl samba45-python samba45-winbind-krb5-locator perl-Parse-Yapp\
perl-Test-Base python2-crypto samba45-common-tools
Rimuovi questi file.
[root@samba4 ~]# rm -rf /etc/krb5.conf
[root@samba4 ~]# rm -rf /etc/samba/smb.conf
Configurazione di Samba 4
Ora procederemo con il provisioning del dominio.
[root@samba4 ~]# samba-tool domain provision --use-rfc2307 --interactive
Realm [SUNIL.CC]:
Domain [SUNIL]:
Server Role (dc, member, standalone) [dc]:
DNS backend (SAMBA_INTERNAL, BIND9_FLATFILE, BIND9_DLZ, NONE) [SAMBA_INTERNAL]:
DNS forwarder IP address (write 'none' to disable forwarding) [4.2.2.1]:
Administrator password:
Retype password:
Looking up IPv4 addresses
Looking up IPv6 addresses
No IPv6 address will be assigned
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=sunil,DC=cc
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=sunil,DC=cc
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 /var/lib/samba/private/krb5.conf
Setting up fake yp server settings
Once the above files are installed, your Samba4 server will be ready to use
Server Role: active directory domain controller
Hostname: samba4
NetBIOS Domain: SUNIL
DNS Domain: sunil.cc
DOMAIN SID: S-1-5-21-1578983437-3114190590-2362936743
[root@samba4 etc]#
Assicurati che le porte siano aperte nel firewall.
[root@samba4 etc]#firewall-cmd --add-port=53/tcp --permanent;firewall-cmd --add-port=53/udp --permanent;firewall-cmd --add-port=88/tcp --permanent;firewall-cmd --add-port=88/udp --permanent;
firewall-cmd --add-port=135/tcp --permanent;firewall-cmd --add-port=137-138/udp --permanent;firewall-cmd --add-port=139/tcp --permanent;
firewall-cmd --add-port=389/tcp --permanent;firewall-cmd --add-port=389/udp --permanent;firewall-cmd --add-port=445/tcp --permanent;
firewall-cmd --add-port=464/tcp --permanent;firewall-cmd --add-port=464/udp --permanent;firewall-cmd --add-port=636/tcp --permanent;
firewall-cmd --add-port=1024-3500/tcp --permanent;firewall-cmd --add-port=3268-3269/tcp --permanent
[root@samba4 ~]# firewall-cmd --reload
Il pacchetto non fornisce lo script di inizializzazione, lo aggiungeremo ora.
[root@samba4 ~]# cat /etc/systemd/system/samba.service
[Unit]
Description= Samba 4 Active Directory
After=syslog.target
After=network.target
[Service]
Type=forking
PIDFile=/var/run/samba.pid
ExecStart=/usr/sbin/samba
[Install]
WantedBy=multi-user.target
[root@samba4 ~]#
[root@samba4 ~]# systemctl enable samba
Created symlink from /etc/systemd/system/multi-user.target.wants/samba.service to /etc/systemd/system/samba.service.
[root@samba4 ~]# systemctl restart samba
Tutti gli altri passaggi sono simili al mio articolo precedente per configurare gli host Windows e Linux, si prega di fare riferimento ad esso
Installazione del controller di dominio Samba4 da sorgente
Creazione della condivisione Samba con supporto ACL di Windows
Dobbiamo configurare ACL estese per samba4. Aggiungi quanto segue nel file smb.conf sotto globale.
[root@samba4 ~]# cat /etc/samba/smb.conf
# Parametri globali
[global]
------------
-------------
vfs objects = acl_xattr
map acl inherit = yes
store dos attributes = yes
------------
-------------
[root@samba4 ~]#
Ora riavvia il servizio Samba.
[root@samba4 ~]# systemctl restart sambaSolo gli utenti e i gruppi che hanno il privilegio SeDiskOperatorPrivilege possono configurare i permessi di condivisione.
[root@samba4 ~]# net rpc rights grant "SUNIL\Domain Admins" SeDiskOperatorPrivilege -U "USER\administrator"
Enter USER\administrator's password:
Successfully granted rights.
[root@samba4 ~]#
Prima di creare la condivisione, dobbiamo assicurarci che il server samba4 si autentichi con se stesso.
Non possiamo fare il metodo abituale poiché non funziona poiché il pacchetto esistente di wing entrerà in conflitto con i pacchetti forniti da RedHat, non possiamo usare sssd qui. Useremo winbind per farlo funzionare.
Si prega di utilizzare il metodo sottostante. Questo è necessario per creare la condivisione samba con permessi specifici.
Installa il pacchetto sottostante.
[root@samba4 ~]#yum -y install authconfig-gtk*Esegui il comando.
[root@samba4 yum.repos.d]# authconfig-tui
seleziona winbind, segui i passaggi successivi.




Non sarai in grado di inserire la password, premi semplicemente ok.
Quindi commenta le righe in /etc/samba/smb.conf e riavvia il servizio samba.
La tua configurazione dovrebbe apparire così:
[root@samba4 ~]# cat /etc/samba/smb.conf
# Parametri globali
[global]
#--authconfig--start-line--
# Generato da authconfig il 2017/05/26 17:23:04
# NON MODIFICARE QUESTA SEZIONE (delimitata da --start-line--/--end-line--)
# Qualsiasi modifica potrebbe essere eliminata o alterata da authconfig in futuro
# workgroup = SUNIL
# password server = samba4.sunil.cc
# realm = SUNIL.CC
# security = ads
# idmap config * : range = 16777216-33554431
# template shell = /sbin/nologin
# kerberos method = secrets only
# winbind use default domain = false
# winbind offline logon = false
#--authconfig--end-line--
netbios name = SAMBA4
realm = SUNIL.CC
workgroup = SUNIL
dns forwarder = 4.2.2.1
server role = active directory domain controller
idmap_ldb:use rfc2307 = yes
vfs objects = acl_xattr
map acl inherit = yes
store dos attributes = yes
[netlogon]
path = /var/lib/samba/sysvol/sunil.cc/scripts
read only = No
[sysvol]
path = /var/lib/samba/sysvol
read only = No
[root@samba4 ~]#
[root@samba4 ~]# systemctl restart samba
Controlla se siamo in grado di popolare gli utenti e i gruppi:
[root@samba4 ~]# wbinfo -u
SUNIL\administrator
SUNIL\sambauser
SUNIL\testuser
SUNIL\krbtgt
SUNIL\guest
[root@samba4 ~]# wbinfo -g
SUNIL\cert publishers
SUNIL\ras and ias servers
SUNIL\allowed rodc password replication group
SUNIL\denied rodc password replication group
SUNIL\dnsadmins
SUNIL\enterprise read-only domain controllers
SUNIL\domain admins
SUNIL\domain users
SUNIL\domain guests
SUNIL\domain computers
SUNIL\domain controllers
SUNIL\schema admins
SUNIL\enterprise admins
SUNIL\group policy creator owners
SUNIL\read-only domain controllers
SUNIL\dnsupdateproxy
[root@samba4 ~]#
Modifica le righe in nsswitch.conf:
[root@samba4 ~]# cat /etc/nsswitch.conf
----------
---------
passwd: files winbind
shadow: files winbind
group: files winbind
hosts: files dns wins
services: files winbind
netgroup: files winbind
---------
----------
Ora controlla se siamo in grado di ottenere il nome utente utilizzando il comando id:
[root@samba4 ~]# id testuser
uid=3000019(SUNIL\testuser) gid=100(users) groups=100(users),3000019(SUNIL\testuser),3000009(BUILTIN\users)
[root@samba4 ~]#
Creare una condivisione Samba
Creerò due condivisioni, una accessibile solo da testuser e l’altra condivisione accessibile da tutti gli utenti nel gruppo utenti di dominio.
La condivisione accessibile da testuser sarà chiamata testshare.
La condivisione accessibile da tutti gli utenti sarà chiamata commonshare.
[root@samba4 ~]# mkdir /testshare
[root@samba4 ~]# mkdir /commonshare
[root@samba4 ~]# chmod 770 /testshare
[root@samba4 ~]# chmod 770 /commonshare
[root@samba4 ~]# chown -R root:testuser /testshare
[root@samba4 ~]# chown -R root:"Domain Users" /commonshare
Ora aggiungi le voci in smb.conf
[root@samba4 ~]# cat /etc/samba/smb.conf
# Parametri globali
[global]
netbios name = SAMBA4
realm = SUNIL.CC
workgroup = SUNIL
dns forwarder = 4.2.2.1
server role = active directory domain controller
idmap_ldb:use rfc2307 = yes
vfs objects = acl_xattr
map acl inherit = yes
store dos attributes = yes
[netlogon]
path = /var/lib/samba/sysvol/sunil.cc/scripts
read only = No
[sysvol]
path = /var/lib/samba/sysvol
read only = No
[TestShare]
comment = Condivisione di test accessibile da testuser
path = /testshare
valid users = SUNIL\testuser
writable = yes
read only = no
force create mode = 0660
create mask = 0770
directory mask = 0770
force directory mode = 0770
access based share enum = yes
hide unreadable = yes
[CommonShare]
comment = Accessibile da tutti gli utenti
path = /commonshare
valid users = "@SUNIL\Domain Users"
writable = yes
read only = no
force create mode = 0660
create mask = 0777
directory mask = 0777
force directory mode = 0770
access based share enum = yes
hide unreadable = yes
[root@samba4 ~]#
Riavvia il servizio samba.
[root@samba4 ~]# systemctl restart sambaAccedi alla condivisione samba come test user.

Qui vedrai sia testshare che commonshare visibili. Ho testato la creazione di file e cartelle sotto testshare.

[root@samba4 /]# cd /testshare/
[root@samba4 testshare]# ls -l
total 8
-rwxrwx---+ 1 SUNIL\testuser users 0 May 27 22:56 1.txt
drwxrwx---+ 2 SUNIL\testuser users 6 May 27 22:56 test
[root@samba4 testshare]#
Ora mi sto connettendo come un utente diverso, solo commonshare è visibile:

Creando file sotto commonshare.
[root@samba4 commonshare]# ls -l
total 8
drwxrwxrwx+ 2 SUNIL\testuser users 6 May 27 23:02 test
drwxrwxrwx+ 2 SUNIL\sambauser users 6 May 27 23:07 test2
[root@samba4 commonshare]#
Questo è come creiamo condivisioni sotto Samba 4.
Ricevi i nuovi post nella tua casella di posta.
Nessuno spam. Disiscriviti in qualsiasi momento.