Product SiteDocumentation Site

11.5. Configurare condivisioni Windows con Samba

Samba is a suite of tools handling the SMB protocol (also known as “CIFS”) on Linux. This protocol is used by Windows for network shares and shared printers.
Samba can also act as an Windows domain controller. This is an outstanding tool for ensuring seamless integration of Linux servers and the office desktop machines still running Windows.

11.5.1. Server Samba

The samba package contains the main two servers of Samba 3, smbd and nmbd.

11.5.1.1. Configurare con debconf

Questo pacchetto imposta una configurazione minimale basata sulle risposte ad alcune domande poste da Debconf durante l'installazione iniziale; questa fase di configurazione può essere ripetuta in seguito con dpkg-reconfigure samba-common samba.
La prima informazione richiesta è il nome del gruppo di lavoro a cui apparterrà il server Samba (la risposta nel nostro caso sarà FALCOTNET). Un'altra domanda chiederà se le password dovranno essere cifrate. La risposta è che dovranno esserlo poiché si tratta di un requisito per la maggior parte dei client Windows moderni, inoltre questo aumenta la sicurezza. Il rovescio della medaglia è che ciò richiede di gestire le password Samba separatamente dalle password Unix.
Il pacchetto propone inoltre di identificare il server WINS attraverso le informazioni fornite dal demone DHCP. Gli amministratori della Falcot Corporation rifiutano questa opzione, poiché intendono utilizzare lo stesso server Samba come server WINS.
The last question is about whether servers should be started by inetd or as stand-alone daemons. Using inetd is only interesting when Samba is rarely used; the Falcot administrators therefore picked stand-alone daemons.

11.5.1.2. Configurazione manuale

11.5.1.2.1. Modifiche a smb.conf
Le necessità della Falcot richiedono che altre opzioni siano modificate nel file di configurazione /etc/samba/smb.conf. Gli estratti seguenti riassumono le modifiche applicate alla sezione [global].
[global]

## Browsing/Identification ###

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

# server string is the equivalent of the NT Description field
   server string = %h server (Samba %v)

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable its WINS Server
   wins support = yes 1

[...]

####### 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 = user 2

# You may wish to use password encryption.  See the section on
# 'encrypt passwords' in the smb.conf(5) manpage before enabling.
   encrypt passwords = true

# If you are using encrypted passwords, Samba will need to know what
# password database type you are using.
   passdb backend = tdbsam

[...]

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

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

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

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

1

Indica che Samba agirà come name server Netbios (WINS) per la rete locale.

2

Questo è il valore predefinito per questo parametro. Ad ogni modo, poiché è un punto chiave per la configurazione di Samba, è raccomandato indicare esplicitamente la propria scelta. Ogni utente deve autenticarsi prima di accedere a qualsiasi condivisione.

3

Comunica a Samba di condividere automaticamente tutte le stampanti locali configurate su CUPS. Rimane possibile restringere l'accesso a queste stampanti aggiungendo delle sezioni appropriate.

4

Specifica il sistema di stampa in uso, CUPS nel nostro caso.
11.5.1.2.2. Aggiungere utenti
Ogni utente Samba necessita di un account sul server. L'account Unix dev'essere creato per primo, quindi l'utente dev'essere registrato nel database di Samba. La creazione dell'account Unix viene eseguita normalmente (utilizzando per esempio adduser).
Un utente esistente viene aggiunto al database di Samba con il comando smbpasswd -a utente: questo comando chiede di inserire la password in modalità interattiva.
Un utente può essere cancellato con il comando smbpasswd -x utente. Un account Samba può anche essere disabilitato temporaneamente con smbpasswd -d utente ed essere riabilitato in seguito con smbpasswd -e utente.
11.5.1.2.3. Passare al controller di dominio
Questa sezione documenta come gli amministratori della Falcot sono andati oltre trasformando il server Samba in un controller di dominio che fornisce profili in roaming (cosa che consente agli utenti di trovare il proprio desktop indipendentemente dalla macchina a cui si collegano).
Inizialmente hanno aggiunto alcune direttive extra nella sezione [global] del file di configurazione:
domain logons = yes              1
preferred master = yes           
logon path = \\%L\profiles\%U    2
logon script = scripts/logon.bat 3

1

Abilita la funzionalità controller di dominio

2

Specifica la posizione delle directory home per gli utenti. Queste sono conservate in una condivisione dedicata, cosa che permette di abilitare opzioni specifiche (in particolare le acl per il profilo, un requisito per la compatibilità con Windows 2000, XP e Vista).

3

Specifica lo script batch (non interattivo) che sarà eseguito sulla macchina Windows client ogniqualvolta viene aperta una sessione. In questo caso /var/lib/samba/netlogon/scripts/logon.bat. Lo script dev'essere in formato DOS dove le linee sono separate da un carattere di ritorno carrello e da un carattere per l'avanzamento di riga. Se il file è stato creato con Linux eseguire unix2dos lo convertirà.
I comandi utilizzati più comunemente in questi script permettono la creazione automatica dei dischi di rete e la sincronizzazione di data ed ora sul sistema.

Esempio 11.27. Il file logon.bat

net time \\ARRAKIS /set /yes
net use H: /home
net use U: \\ARRAKIS\utils
Vengono inoltre create due condivisioni aggiuntive, e le relative directory associate:
[netlogon]
comment = Network Logon Service
path = /var/lib/samba/netlogon
guest ok = yes
writable = no
share modes = no

[profiles]
comment = Profile Share
path = /var/lib/samba/profiles
read only = No
profile acls = Yes
Devono anche essere create le directory home per tutti gli utenti (come /var/lib/samba/profiles/utente) ed ognuna dev'essere di proprietà dell'utente corrispondente.

11.5.2. Client Samba

The client features in Samba allow a Linux machine to access Windows shares and shared printers. The required programs are available in the cifs-utils and smbclient packages.

11.5.2.1. Il programma smbclient

Il programma smbclient interroga i server SMB. Accetta una opzione -U utente per connettersi al server attraverso una specifica identità. smbclient //server/condivisione accede alla condivisione con una modalità interattiva simile alla riga di comando dei client FTP. smbclient -L server elenca tutte le condivisioni disponibili (e visibili) sul server.

11.5.2.2. Montare le condivisioni Windows

The mount command allows mounting a Windows share into the Linux filesystem hierarchy (with the help of mount.cifs provided by cifs-utils).

Esempio 11.28. Montare una condivisione Windows

mount -t cifs //arrakis/shared /shared \
      -o credentials=/etc/smb-credentials
The /etc/smb-credentials file (which must not be readable by users) has the following format:
username = utente
password = password
Other options can be specified on the command-line; their full list is available in the mount.cifs(1) manual page. Two options in particular can be interesting: uid and gid allow forcing the owner and group of files available on the mount, so as not to restrict access to root.
A mount of a Windows share can also be configured in /etc/fstab:
//server/shared /shared cifs credentials=/etc/smb-credentials
Unmounting a SMB/CIFS share is done with the standard umount command.

11.5.2.3. Stampare su una stampante condivisa

CUPS è una soluzione elegante per stampare da una workstation Linux su di una stampante condivisa da una macchina Windows. Quando il smbclient è installato, CUPS consente l'installazione automatica delle stampanti Windows condivise.
Seguono i passi richiesti:
  • Enter the CUPS configuration interface: http://localhost:631/admin
  • Click on “Add Printer”.
  • Choose the printer device, pick “Windows Printer via SAMBA”.
  • Enter the connection URI for the network printer. It should look like the following:
    smb://utente:password@server/stampante.
  • Enter the name that will uniquely identify this printer. Then enter the description and location of the printer. Those are the strings that will be shown to end users to help them identify the printers.
  • Indicate the manufacturer/model of the printer, or directly provide a working printer description file (PPD).
Voilà, la stampante è operativa!