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 4, smbd and nmbd.

11.5.1.1. Configurare con debconf

The package sets up a minimal configuration during the initial installation but you should really run dpkg-reconfigure samba-common to adapt it:
The first piece of required information is the name of the workgroup where the Samba server will belong (the answer is FALCOTNET in our case).
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.

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

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

[...]

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

# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller". 
#
# Most people will want "standalone sever" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
   server role = standalone server

# "security = user" is always a good idea. This will require a Unix account
# in this server for every user accessing the server.
   security = user 2

[...]

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.
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.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.24. 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!