Old:Samba e OpenLDAP: creare un controller di dominio con Ubuntu Server Configurare Client Linux: differenze tra le versioni

Da Guide@Debianizzati.Org.
Vai alla navigazione Vai alla ricerca
mNessun oggetto della modifica
m (obsoleta)
Riga 1: Riga 1:
{{Samba e OpenLDAP su Ubuntu server}}
{{Old:Template:Samba e OpenLDAP su Ubuntu server}}
== Introduzione ==
== Introduzione ==
In questa sezione illustrerò come configurare samba e PAM su un client Ubuntu Desktop 10.10 affinché si connettano ad un dominio samba con backend ldap.
In questa sezione illustrerò come configurare samba e PAM su un client Ubuntu Desktop 10.10 affinché si connettano ad un dominio samba con backend ldap.
Riga 687: Riga 687:
# chmod 771 /home/utente
# chmod 771 /home/utente
</pre>
</pre>
[[Categoria:Samba]][[Categoria:Reti con Windows]]

Versione delle 15:21, 7 dic 2019

Emblem-important.png Attenzione. Questa guida è obsoleta. Viene mantenuta sul Wiki solo per motivi di natura storica e didattica.


Samba e OpenLDAP: creare un controller di dominio con Ubuntu Server

Sommario

  1. Introduzione
  2. Configurazione DHCP e DNS
  3. Installazione e Configurazione LDAP Server
  4. Installazione e Configurazione Autenticazione LDAP
  5. Configurazione cittografia TLS
  6. Installazione e Configurazione Samba PDC
  7. Installazione e Configurazione SMBLDAP-TOOLS
  8. Popolamento database LDAP
  9. Configurazione Quote Utenti
  10. Aggiungere gli utenti di dominio
  11. Testare la rete
  12. Installazione e configurazione PHPLDAPADMIN
  13. Configurazione Client Linux
  14. Comandi Utili e altro
  15. Approfondimenti

Introduzione

In questa sezione illustrerò come configurare samba e PAM su un client Ubuntu Desktop 10.10 affinché si connettano ad un dominio samba con backend ldap.

Configurazione Samba

Una volta installato samba:

$ apt-get install samba samba-doc nscd

Si passa alla fase della configurazione di smb.conf con security = DOMAIN (per l'uso di un NT4/samba domain):

[global]

## Browsing/Identification ###

# Change this to the workgroup/NT-domain name your Samba server will part of
   workgroup = DOMINIO

# server string is the equivalent of the NT Description field
   server string = %h server (Samba, Ubuntu)
   netbios name = Hostname
# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable its WINS Server
#   wins support = no

# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
#   wins server = 192.168.2.1
   password server = *
#   dns proxy = no

# What naming service and in what order should we use to resolve host names
# to IP addresses
   name resolve order = lmhosts host wins bcast 

#### Networking ####

# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
#   interfaces = 127.0.0.0/8 eth0

# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself.  However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
#   bind interfaces only = yes



#### Debugging/Accounting ####
log level = 0 passdb:6 auth:10 vfs:5 acls:3 msdfs:3
log file = /var/log/samba/%U.%m.log

# Cap the size of the individual log files (in KiB).
   max log size = 1000

# If you want Samba to only log through syslog then set the following
# parameter to 'yes'.
#   syslog only = no

# We want Samba to log a minimum amount of information to syslog. Everything
# should go to /var/log/samba/log.{smbd,nmbd} instead. If you want to log
# through syslog you should set the following parameter to something higher.
   syslog = 0

# Do something sensible when Samba crashes: mail the admin a backtrace
   panic action = /usr/share/samba/panic-action %d


####### Authentication #######

# "security = user" is always a good idea. This will require a Unix account
# in this server for every user accessing the server. See
# /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html
# in the samba-doc package for details.
   security = DOMAIN

# You may wish to use password encryption.  See the section on
# 'encrypt passwords' in the smb.conf(5) manpage before enabling.
   encrypt passwords = true
#   password server = *
# If you are using encrypted passwords, Samba will need to know what
# password database type you are using.  
   passdb backend = ldapsam:ldap://192.168.2.1:389
   ldap admin dn = cn=admin,dc=dominio,dc=local
   ldap suffix = dc=dominio,dc=local
   ldap user suffix = ou=users
   ldap group suffix = ou=groups
   ldap idmap suffix = ou=idmap
   ldap machine suffix = ou=computers
   idmap backend = ldap:ldap://192.168.2.1:389
#  obey pam restrictions = yes

# This boolean parameter controls whether Samba attempts to sync the Unix
# password with the SMB password when the encrypted SMB password in the
# passdb is changed.
#   unix password sync = yes

# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de> for
# sending the correct chat script for the passwd program in Debian Sarge).
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .

# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
  pam password change = yes
  ldap passwd sync = yes
# This option controls how unsuccessful authentication attempts are mapped
# to anonymous connections
#   map to guest = bad user
#   map untrusted to domain = Yes

########## Domains ###########

# Is this machine able to authenticate users. Both PDC and BDC
# must have this setting enabled. If you are the BDC you must
# change the 'domain master' setting to no
#
   domain logons = no
   domain master = no
   local master = no 
#
# The following setting only takes effect if 'domain logons' is set
# It specifies the location of the user's profile directory
# from the client point of view)
# The following required a [profiles] share to be setup on the
# samba server (see below)
#   logon path = \\sole\profiles\%U
# Another common choice is storing the profile in the user's home directory
# (this is Samba's default)
#   logon path = \\%N\%U\profile

# The following setting only takes effect if 'domain logons' is set
# It specifies the location of a user's home directory (from the client
# point of view)
#   logon drive = H:
#   logon home = \\sole\profiles\%U

# The following setting only takes effect if 'domain logons' is set
# It specifies the script to run during logon. The script must be stored
# in the [netlogon] share
# NOTE: Must be store in 'DOS' file format convention
;   logon script = logon.cmd

# This allows Unix users to be created on the domain controller via the SAMR
# RPC pipe.  The example command creates a user account with a disabled Unix
# password; please adapt to your needs
; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u

# This allows machine accounts to be created on the domain controller via the 
# SAMR RPC pipe.  
# The following assumes a "machines" group exists on the system
; add machine script  = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u

# This allows Unix groups to be created on the domain controller via the SAMR
# RPC pipe.  
; add group script = /usr/sbin/addgroup --force-badname %g

########## Printing ##########

# If you want to automatically load your printer list rather
# than setting them up individually then you'll need this
#   load printers = yes

# lpr(ng) printing. You may wish to override the location of the
# printcap file
#   printing = cups
;   printcap name = /etc/printcap

# CUPS printing.  See also the cupsaddsmb(8) manpage in the
# cupsys-client package.
   printing = cups
   printcap name = cups

############ Misc ############

# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting
;   include = /home/samba/etc/smb.conf.%m

# Most people will find that this option gives better performance.
# See smb.conf(5) and /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/speed.html
# for details
# You may want to add the following on a Linux system:
#         SO_RCVBUF=8192 SO_SNDBUF=8192
   socket options = TCP_NODELAY

# The following parameter is useful only if you have the linpopup package
# installed. The samba maintainer and the linpopup maintainer are
# working to ease installation and configuration of linpopup and samba.
;   message command = /bin/sh -c '/usr/bin/linpopup "%f" "%m" %s; rm %s' &

# Domain Master specifies Samba to be the Domain Master Browser. If this
# machine will be configured as a BDC (a secondary logon server), you
# must set this to 'no'; otherwise, the default behavior is recommended.
#   domain master = auto

# Some defaults for winbind (make sure you're not using the ranges
# for something else.)
   idmap uid = 10000-20000
   idmap gid = 10000-20000
;   template shell = /bin/bash
#   winbind nss info = template
#   template homedir = \\sole\profiles\%U
# The following was the default behaviour in sarge,
# but samba upstream reverted the default because it might induce
# performance issues in large organizations.
# See Debian bug #368251 for some of the consequences of *not*
# having this setting and smb.conf(5) for details.
   winbind separator = + 
#   winbind trusted domains only = yes
   winbind use default domain = Yes
   winbind enum groups = yes
   winbind enum users = yes
#   winbind nested groups = Yes
# Setup usershare options to enable non-root users to share folders
# with the net usershare command.

# Maximum number of usershare. 0 (default) means that usershare is disabled.
;   usershare max shares = 100

# Allow users who've been granted usershare privileges to create
# public shares, not just authenticated ones
   usershare allow guests = yes

#======================= Share Definitions =======================

# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each 
# user's home director as \\server\username
[homes]
   comment = Home Directories
   browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
   read only = yes

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
;   create mask = 0700

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
;   directory mask = 0700

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server. Un-comment the following parameter
# to make sure that only "username" can connect to \\server\username
# The following parameter makes sure that only "username" can connect
#
# This might need tweaking when using external authentication schemes
   valid users = %S

# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]
;   comment = Network Logon Service
;   path = /home/samba/netlogon
;   guest ok = yes
;   read only = yes
;   share modes = no

# Un-comment the following and create the profiles directory to store
# users profiles (see the "logon path" option above)
# (you need to configure Samba to act as a domain controller too.)
# The path below should be writable by all users so that their
# profile directory may be created the first time they log on
;[profiles]
;   comment = Users profiles
;   path = /home/samba/profiles
;   guest ok = no
;   browseable = no
;   create mask = 0600
;   directory mask = 0700

[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no

Non è stato configurato winbind perché ldap ha già il modulo di autenticazione e ci pensa lui ad autenticare gli utenti.
Gli unici comandi nuovi sono:

security = DOMAIN
password server = *

Questi devono essere settati e per quanto concerne il wins server l'indirizzo dipende dall'IP che avete assegnato al server.

Autenticazione PAM e NSS

Ora dobbiamo prima installare i pacchetti:

# apt-get install libnss-ldap libpam-ldap

ora configuriamo come Samba e OpenLDAP: creare un controller di dominio con Ubuntu Server Autenticazione LDAP, rispondendo a tutte le domande.
Il file di configurazione ldap.conf dovrebbe essere, più o meno, come questo:

# Your LDAP server. Must be resolvable without using LDAP.
# Multiple hosts may be specified, each separated by a 
# space. How long nss_ldap takes to failover depends on
# whether your LDAP client library supports configurable
# network or connect timeouts (see bind_timelimit).
host 192.168.2.1

# The distinguished name of the search base.
base dc=dominio,dc=local

# Another way to specify your LDAP server is to provide an
uri ldap://192.168.2.1
# Unix Domain Sockets to connect to a local LDAP Server.
#uri ldap://127.0.0.1/
#uri ldaps://127.0.0.1/   
#uri ldapi://%2fvar%2frun%2fldapi_sock/
# Note: %2f encodes the '/' used as directory separator

# The LDAP version to use (defaults to 3
# if supported by client library)
ldap_version 3

# The distinguished name to bind to the server with.
# Optional: default is to bind anonymously.
binddn cn=admin,dc=dominio,dc=local

# The credentials to bind with. 
# Optional: default is no credential.
bindpw secret

# The distinguished name to bind to the server with
# if the effective user ID is root. Password is
# stored in /etc/ldap.secret (mode 600)
#rootbinddn cn=admin,dc=dominio,dc=local

# The port.
# Optional: default is 389.
port 389
#port 636
# The search scope.
scope sub
#scope one
#scope base

# Search timelimit
timelimit 50

# Bind/connect timelimit
bind_timelimit 50

# Reconnect policy: hard (default) will retry connecting to
# the software with exponential backoff, soft will fail
# immediately.
bind_policy soft

# Idle timelimit; client will close connections
# (nss_ldap only) if the server has not been contacted
# for the number of seconds specified below.
#idle_timelimit 3600

# Filter to AND with uid=%s
#pam_filter objectclass=account

# The user ID attribute (defaults to uid)
pam_login_attribute uid

# Search the root DSE for the password policy (works
# with Netscape Directory Server)
#pam_lookup_policy yes

# Check the 'host' attribute for access control
# Default is no; if set to yes, and user has no
# value for the host attribute, and pam_ldap is
# configured for account management (authorization)
# then the user will not be allowed to login.
#pam_check_host_attr yes

# Check the 'authorizedService' attribute for access
# control
# Default is no; if set to yes, and the user has no
# value for the authorizedService attribute, and
# pam_ldap is configured for account management
# (authorization) then the user will not be allowed
# to login.
#pam_check_service_attr yes

# Group to enforce membership of
#pam_groupdn cn=PAM,ou=Groups,dc=padl,dc=com

# Group member attribute
pam_member_attribute memberUid

# Specify a minium or maximum UID number allowed
#pam_min_uid 0
#pam_max_uid 0

# Template login attribute, default template user
# (can be overriden by value of former attribute
# in user's entry)
#pam_login_attribute userPrincipalName
#pam_template_login_attribute uid
#pam_template_login nobody

# HEADS UP: the pam_crypt, pam_nds_passwd,
# and pam_ad_passwd options are no
# longer supported.
#
# Do not hash the password at all; presume
# the directory server will do it, if
# necessary. This is the default.
#pam_password md5

# Hash password locally; required for University of
# Michigan LDAP server, and works with Netscape
# Directory Server if you're using the UNIX-Crypt
# hash mechanism and not using the NT Synchronization
# service. 
#pam_password crypt

# Remove old password first, then update in
# cleartext. Necessary for use with Novell
# Directory Services (NDS)
#pam_password clear_remove_old
#pam_password nds

# RACF is an alias for the above. For use with
# IBM RACF
#pam_password racf

# Update Active Directory password, by
# creating Unicode password and updating
# unicodePwd attribute.
#pam_password ad

# Use the OpenLDAP password change
# extended operation to update the password.
pam_password exop

# Redirect users to a URL or somesuch on password
# changes.
#pam_password_prohibit_message Please visit http://internal to change your password.

# RFC2307bis naming contexts
# Syntax:
# nss_base_XXX		base?scope?filter
# where scope is {base,one,sub}
# and filter is a filter to be &'d with the
# default filter.
# You can omit the suffix eg:
# nss_base_passwd	ou=People,
# to append the default base DN but this
# may incur a small performance impact.
nss_base_passwd	dc=dominio,dc=local?sub
nss_base_shadow	dc=dominio,dc=local?sub
nss_base_group	ou=groups,dc=dominio,dc=local?one
#nss_base_hosts		ou=Hosts,dc=padl,dc=com?one
#nss_base_services	ou=Services,dc=padl,dc=com?one
#nss_base_networks	ou=Networks,dc=padl,dc=com?one
#nss_base_protocols	ou=Protocols,dc=padl,dc=com?one
#nss_base_rpc		ou=Rpc,dc=padl,dc=com?one
#nss_base_ethers	ou=Ethers,dc=padl,dc=com?one
#nss_base_netmasks	ou=Networks,dc=padl,dc=com?ne
#nss_base_bootparams	ou=Ethers,dc=padl,dc=com?one
#nss_base_aliases	ou=Aliases,dc=padl,dc=com?one
#nss_base_netgroup	ou=Netgroup,dc=padl,dc=com?one

# attribute/objectclass mapping
# Syntax:
#nss_map_attribute	rfc2307attribute	mapped_attribute
#nss_map_objectclass	rfc2307objectclass	mapped_objectclass

# configure --enable-nds is no longer supported.
# NDS mappings
#nss_map_attribute uniqueMember member

# Services for UNIX 3.5 mappings
#nss_map_objectclass posixAccount User
#nss_map_objectclass shadowAccount User
#nss_map_attribute uid msSFU30Name
#nss_map_attribute uniqueMember msSFU30PosixMember
#nss_map_attribute userPassword msSFU30Password
#nss_map_attribute homeDirectory msSFU30HomeDirectory
#nss_map_attribute homeDirectory msSFUHomeDirectory
#nss_map_objectclass posixGroup Group
#pam_login_attribute msSFU30Name
#pam_filter objectclass=User
#pam_password ad

# configure --enable-mssfu-schema is no longer supported.
# Services for UNIX 2.0 mappings
#nss_map_objectclass posixAccount User
#nss_map_objectclass shadowAccount user
#nss_map_attribute uid msSFUName
#nss_map_attribute uniqueMember posixMember
#nss_map_attribute userPassword msSFUPassword
#nss_map_attribute homeDirectory msSFUHomeDirectory
#nss_map_attribute shadowLastChange pwdLastSet
#nss_map_objectclass posixGroup Group
#nss_map_attribute cn msSFUName
#pam_login_attribute msSFUName
#pam_filter objectclass=User
#pam_password ad

# RFC 2307 (AD) mappings
#nss_map_objectclass posixAccount user
#nss_map_objectclass shadowAccount user
#nss_map_attribute uid sAMAccountName
#nss_map_attribute homeDirectory unixHomeDirectory
#nss_map_attribute shadowLastChange pwdLastSet
#nss_map_objectclass posixGroup group
#nss_map_attribute uniqueMember member
#pam_login_attribute sAMAccountName
#pam_filter objectclass=User
#pam_password ad

# configure --enable-authpassword is no longer supported
# AuthPassword mappings
#nss_map_attribute userPassword authPassword

# AIX SecureWay mappings
#nss_map_objectclass posixAccount aixAccount
#nss_base_passwd ou=aixaccount,?one
#nss_map_attribute uid userName
#nss_map_attribute gidNumber gid
#nss_map_attribute uidNumber uid
#nss_map_attribute userPassword passwordChar
#nss_map_objectclass posixGroup aixAccessGroup
#nss_base_group ou=aixgroup,?one
#nss_map_attribute cn groupName
#nss_map_attribute uniqueMember member
#pam_login_attribute userName
#pam_filter objectclass=aixAccount
#pam_password clear

# Netscape SDK LDAPS
#ssl on

# Netscape SDK SSL options
#sslpath /etc/ssl/certs

# OpenLDAP SSL mechanism
# start_tls mechanism uses the normal LDAP port, LDAPS typically 636
#ssl start_tls
ssl off

# OpenLDAP SSL options
# Require and verify server certificate (yes/no)
# Default is to use libldap's default behavior, which can be configured in
# /etc/openldap/ldap.conf using the TLS_REQCERT setting.  The default for
# OpenLDAP 2.0 and earlier is "no", for 2.1 and later is "yes".
#tls_checkpeer yes

# CA certificates for server certificate verification
# At least one of these are required if tls_checkpeer is "yes"
#tls_cacertfile /etc/ssl/ca.cert
#tls_cacertdir /etc/ssl/certs

# Seed the PRNG if /dev/urandom is not provided
#tls_randfile /var/run/egd-pool

# SSL cipher suite
# See man ciphers for syntax
#tls_ciphers TLSv1

# Client certificate and key
# Use these, if your server requires client authentication.
#tls_cert
#tls_key

# Disable SASL security layers. This is needed for AD.
#sasl_secprops maxssf=0

# Override the default Kerberos ticket cache location.
#krb5_ccname FILE:/etc/.ldapcache

# SASL mechanism for PAM authentication - use is experimental
# at present and does not support password policy control
#pam_sasl_mech DIGEST-MD5
nss_initgroups_ignoreusers avahi,avahi-autoipd,backup,bin,couchdb,daemon,games,gdm,gnats,hplip,irc,kernoops,libuuid,list,lp,mail,man,messagebus,news,proxy,pulse,root,rtkit,saned,speech-dispatcher,sync,sys,syslog,usbmux,uucp,www-data

Ricordatevi di settare l'URI secondo l'indirizzo corrispondente del vostro server ldap che avete settato in /etc/default/slapd alla voce SLAPD_SERVICES (es. ldap://192.168.2.1:389), cancellate ldaps:// se non avete settato un TLS. Ora configuriamo nsswitch.conf così:

passwd: files ldap
group: files ldap
shadow: files ldap

hosts:          files dns wins
networks:       files dns

protocols:     db files
services:      db files
ethers:        db files
rpc:           db files

netgroup: nis

Ora eseguiamo da terminale:

$ pam-auth-update

e selezioniamo ldap e deselezioniamo winbind. Dopodiché aprire /etc/pam.d/common-password e settiamo così:

password	[success=2 default=ignore]	pam_unix.so obscure sha512
password	[success=1 user_unknown=ignore default=die]	pam_ldap.so try_first_pass

Dalla seconda voce deve essere cancellato use_authok che si trova prima di try_first_pass, altrimenti non vi permetterà di cambiare la password.
Vi avviso che se settate agli utenti una shell /bin/false il terminale client non si aprirà, perciò vi conviene settare una shell /bin/ bash a tutti gli utenti.

Aggancio al dominio e test

Ora è arrivato il momento di agganciare il client al dominio con:

$ net rpc join -S SERVER -U root%secret

una volta ottenuto:

Join to 'DOMINIO' is OK

Riavviare tutto edopo eseguire:

$ getent passwd
$ getent group

Ora dovrebbero comparirvi l'elenco degli utenti (anche di dominio) e i gruppi (inclusi quelli di dominio).
Ricordatevi di settare i permessi di scrittura della cartella /home al gruppo cui fanno parte gli utenti (es. Domain Users), altrimenti al log in non verrà creata la cartella utente e si bloccherà tutto.

$ chown -R root:root /home
$ chmod -R 755 /home

Non vi resta che loggarvi come utenti di dominio.

Esportare cartella Home

Lato server

Installiamo i servizi NFS:

# apt-get install portmap nfs-kernel-server nfs-common

Per indicare al server quali saranno le cartelle che dovranno essere condivise modifichiamo il file /etc/exports:

/home 192.168.2.0/24(rw)

Se volete condividere la cartella dell’esempio precedente, ma in sola lettura:

/home 192.168.2.0/24(ro)

Adesso possiamo rendere il sistema più sicuro specificando quali client possono accedere al PC e quali invece no.

Negheremo l'accesso a tutti i client tranne ad alcuni, la nostra riga in /etc/hosts.deny dovrà essere:

portmap mountd nfsd statd lockd rquotad : ALL EXCEPT 192.168.2.0/24

Lato Client

Installiamo, nel caso non fossero già presenti, i pacchetti necessari:

# apt-get install portmap nfs-common

Possiamo montare la condivisione direttamente nel file /etc/fstab per averla disponibile automaticamente all'avvio.

Per fare ciò modifichiamo il file /etc/fstab:

ip_server:/home /home nfs defaults 0 2

Riavviare tutto.


N.B.:Per evitare eventuali problemi al log in sul client, settare i permessi delle cartelle utenti della home del server nel seguente modo:

# chown utente:root /home/utente
# chmod 771 /home/utente