Linux - Installing and configuring Samba

January 2017

What is Samba?

Samba ( is a free file server for Linux ( GNU/GPL license) compatible with Microsoft Windows networks. That is to say, it allows you to seamlessly share files and printers between computers on a Microsoft Window network, via a Linux server. The Linux server will be considered as a Windows NT server by the Windows clients.

How Samba works?

The protocol allowing communication between Windows and Linux machines is called SMB (Server Message Block). Developed by Microsoft in 1987, based on a concept developed by IBM in 1985 (NetBIOS), the protocol relies on NetBEUI (as well as TCP/IP). The advantage of TCP/IP is that it has been widely adopted. TCP/IP is implemented on most operating systems (Unix, Linux, AmigaOS, MacOS, OS/2, ...). according to the following scheme:


Network driver

The architecture

Samba consist of a server and a client. It also provide a few tools to test the configuration..etc
  • The server consists of two applications (called deamons)
    • smbd, core server, providing authentication and access to resources
    • nmbd, to display the services offered by Samba
  • client: smbclient is a linux client providing an interface to transfer files, view printers..
  • smbtar: to make a transfer to or from a TAR file under linux
  • testparm: to check the syntax of the smb.conf file (the Samba configuration file)

Installing Samba

Before installing Samba, you will need to recover the RPM files or sources, and add TCP/IP and NetBIOS protocols on the client machines.
The installation (unlike the configuration) is very simple to implement. Just as a first step to get the RPMs and install them:
rpm -ivh samba-common-2.0.6-x.i386.rpm 
rpm -ivh samba-2.0.6-x.i386.rpm 
rpm -ivh samba-client-2.0.6-x.i386.rpm

or you can use:
rpm -ivh samba-*.rpm

Samba - First launch

After installation, you can start the Samba server (no file sharing or printer) by running the following command:
/etc/rc.d/init.d/smb start

The server should return the following lines:
Starting SMB services : 
Starting NMB services:

The following command will to check that the two daemons have been correctly launched:
/etc/rc.d/init.d/smb status 
smbd (pid 1054) is running... 
nmbd (pid 1056) is running...

This command allows you to restart Samba:
/etc/rc.d/init.d/smb restart

But it is recommended to make use of the following two commands:
/etc/rc.d/init.d/smb stop 
/etc/rc.d/init.d/smb start

Configuring Samba

Samba configuration is done through a single configuration file: smb.conf. This file is located in the /usr/local/samba/lib directory.
This file describes the resources that we want to share and the associated permissions/restrictions. The smb.conf file contains several sections (each referenced by a line (headings) containing the name of the section in square brackets), each comprising a set of parameter of the following type: attribute = value .
Note that: comments begin with # .

There are three main sections:
  • The [global] section defines the general settings of the server.
  • The [homes] section defines the sharing settings of a directory.
  • The [printers] section defines the shared printers settings for the server.

[Global] section

Here is an example of [global] section:


 # Same group name as the one for Windows 
workgroup = UNDERTAKER 
 # No guest account 
guest account = nobody ; 
 # Multi-user access 
share modes = yes ; 
 # IP address of the network card of the server 
 # subnet mask 
interfaces = 
 # Location of the printcap file 
printcap = /etc/printcap 
 # Share all printers defined in printcap 
load printers = yes 
 # Samba log file 
log level = 1 
log file = /var/log/samba/log.%m 
 # security mode : (user/share/server) 
security = user 
 # Restrict access to certain subnets 
hosts allow = 15.144. 127. 
 # Prevent access to certain machines 
hosts allow = 15.144.  EXCEPT

Sharing the home directory

The [homes] section is used to define access to the home directory of each user. Here is a sample section:


# commentaire visible depuis le voisinage reseau 
comment =Répertoire personnel 
# affichage de la ressource pour tous 
browseable = no 
# possibilité d'écrire sur la ressource 
writable = yes 
create mask = 0750 

Sharing a custom directory

It is possible to define a custom access to any directory on the machine by creating a section having the name of the directory:

An example:


# commentaire visible depuis le voisinage reseau 
comment = Répertoire Ca Marche 
# chemin d'acces a la ressource 
path = /home/ccm 
# affichage de la ressource pour tous 
browseable = no 
# chemin d'acces a la ressource 
public = no 
# utilisateur autorise a acceder a la ressource 
user = jeff,meandus,tittom 
# possibilité d'écrire sur la ressource 
writable = yes 
create mask = 0750 

Sharing the CD-ROM drive

It is possible to share a CD-ROM drive (it should be pre-assembled), for example by creating a [cd-rom] section as follows:


# commentaire visible depuis le voisinage reseau 
comment = lecteur de CD-ROM 
# chemin d'accès au lecteur 
path = /mnt/cdrom 
# accessible à tous 
public = yes 
# impossibilité d'écrire sur la ressource 
writable = no 
create mask = 0750  

Test the Configuration

The testparm program allows you to check the syntax of the configuration file (smb.conf). It is recommended to run this utility each time you manually edit the smb.conf file. The testparm syntax is as follows:
testparm smb.conf

If it returns no error message, the syntax of the smb.conf file is correct (it only checks the syntax, not the operation).
In order to correctly visualize the results, you can redirect the output to a file using the following command:
testparm smb.conf > /directory/file

Access a Samba resource under Linux

The Samba client (smbclient) provide a command line interface to access Samba resources from a Unix machine.
smbclient will first verify the existence of a Samba server on the network and list the resources it shares with the following command:
smbclient server_name_smb

Once the resources are identified, it is possible to access each of them with the following command:
smbclient \\\server_name_smb\\ressource -U username

The user will be prompted to enter. Then simply send the FTP commands to send/receive files or browse the directories of the resource.
Access to a printer is done using the following command
smbclient \\\server_name_smb\\ressource -P

The printing of the /usr/local/samba/lib/etc.conf file is done using the following command:
print /usr/local/samba/lib/etc.conf

To view the print queue:

To stop smbclient:

Send a message

The Samba client also allows you to send messages via a LanManager client (as long as the remote machine can handle this type of message, such as with WinPopUp). The syntax for sending a message (less than 1600 bytes) is as follows:
smbclient -M machine_name

When you have finished writing the message, press Ctrl + D.

Mounting a shared resource

The smbmount and smbumount utilities allows you to mount/unmount SMB resources as a remote file system (as long as the kernel supports the SMB file system).
To mount a resource:
smbmount //servername_smb /mount_point

To un-mount a resource:
smbumount /mount_point

Original document published on


Published by jak58. Latest update on April 23, 2013 at 10:20 AM by jak58.
This document, titled "Linux - Installing and configuring Samba," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (