How to install Samba server and configure a network share

Samba is a very useful tool. It provides file and print services between computers running Microsoft Windows and computers running Linux. It can integrate with a Windows domain too.  Samba is a re-implementation of the SMB / CIFS networking protocol. The name Samba comes from SMB (Server Message Block), the name of the standard protocol used by the Microsoft Windows network file system.

The objective of this note is to help with the configuration of a Samba server on a Debian 9 Stretch web server (local development machine).

1) Samba Installation

Install Samba with the command sudo apt-get install samba

Debian 9 Samba Installation
Debian 9 Samba Installation

For testing it’s handy to install the Samba Client too. Install with sudo apt-get install smbclient .

You can check if the installation was successful by running whereis samba .

The status of the Samba daemon is available with the command systemctl status smbd .

Samba Status
Samba Status

2) Samba configuration & network share

The Samba configuration file is located here /etc/samba/smb.conf . Make a backup of this file first with cp /etc/samba/smb.conf /etc/samba/smb.conf_BK .

You can verify the default configure using the Samba client, run smbclient -L localhost .

Create a new directory for the share mkdir /tmp/testsambashare/ and update the smb.conf  file using sudo nano /etc/samba/smb.conf .

At the bottom of the smb.conf  file, add the following lines:

[sambashare]
   comment = Test Samba
   path = /tmp/testsambashare
   read only = no
   browsable = yes

Press CTRL + o to save and CTRL + x to exit from the nano text editor.

Restart Samba to apply the configuration updates with sudo service smbd restart or sudo /etc/init.d/smbd restart or sudo systemctl restart smbd .

Go to a Windows machine, open Explorer and browse the network or type the address of the Debian server in directly like this \\NEPTUNE or by IP address \\10.0.0.58 . You will see the Samba share. Note, NEPTUNE is the name of our Debian server. It has a non routable IP address of 10.0.058. Substitute with your IP address or server name.

Windows Explorer Samba Share
Windows Explorer Samba Share

3) Samba user accounts

Samba has its own user “password” management system (it doesn’t use the system account password). Existing users must also exist in /etc/passwd . To add a Samba password for an existing user account run sudo smbpasswd -a <username> .

Samba smbpasswd
Samba smbpasswd

4) Connect to the share from a Windows PC

Go back to your Windows computer. Open up Explorer and connect to the Samba server using \\NEPTUNE or by IP address \\10.0.0.58 . Enter the username and Samba password to connect.

Windows Explorer Login Samba
Windows Explorer Login Samba

 

 

You May Also Like