Samba is a powerful open-source tool that allows Windows-like sharing of files and printers in a network on Linux systems. It enables the coexistence and interaction of Linux and Windows machines on the same network. It is installed on the Linux server that hosts the files to be shared. These shared files can then be accessed by any authorized Linux or Windows client on the same network.

This article will explain how to install and configure the Samba server on a Debian system. We will also learn how to access these shared files from Linux or Windows machines.

We have used Debian 10 to execute the commands and procedures mentioned in this article. However, the commands and procedures work almost exactly the same in other Linux distributions.

Installation of Samba on Debian 10

Launch the Terminal in your Debian OS. Go to the Activities tab in the top left corner of your desktop. Then in the search bar, type the keyword terminal. When the search result appears, click on the Terminal icon to open it.

In the Terminal, enter the following command to install the Samba server.

$ sudo apt install samba

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

It might ask for confirmation by providing you with a Y/n option. Hit y to continue the installation process and Samba will be installed on your system.

During installation, it might ask if you want to use WINS settings from DHCP. If your server is using a static IP address, select NO.

Verifying SAMBA installation

To verify the installation, check the status of the samba service “nmbd”. This service starts automatically upon the installation of Samba.

$ sudo systemctl status nmbd

If the samba server is installed and running successfully, you will see the Active(running) status.

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

If the service does not start automatically, run this command to start it manually:

$ sudo systemctl start nmbd

Configuring Samba

Once the installation of the Samba server is completed, it’s time now to configure it. The samba configuration file smb.conf is located at the /etc/samba directory. In this file, we specify the folder and printers that we want to share along with their permissions and operational parameters. Samba reviews its configuration file after a certain amount of time and updates any changes.

Follow the below steps to perform configurations:

Step 1: Create a directory for sharing files through Samba. This directory will keep the files that need to be shared. Run the following command to create a new directory under the root directory.

$sudo mkdir /samba

Step 2: Now we will need to edit the configuration file smb.conf. Before editing the configuration file, make sure to create a backup of this file in the same or another directory. Execute the following command to create a backup of smb.conf file.

$ sudo cp /etc/samba/smb.conf ~/Documents smb_backup.conf

This command will create a backup at the ~/Documents directory

Step 3: Now edit the original configuration file using any text editor like Vim, Nano, or Gedit. We are using here Nano editor:

$ sudo nano /etc/samba/smb.conf

Scroll down to the bottom of the smb.conf and add the following lines:

[samba-share]
comment = Samba on Debian
path = /samba
read-only = no
browsable = yes

Where

  • [samba-share] = name of the samba share
  • comment= brief description of the share
  • Path= Path of the shared directory.
  • Read-only = Set shared directory as readable
  • Browsable = to include the share in the share list or not

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

Once done, press Ctrl O and Ctrl X simultaneously to save and quit the file.

Setting up User Account

Now we will need the setup user account for samba. The Samba user must have to be the system user and therefore should exist in the /etc/password file. If a user does not already exist, you will first need to create it. Otherwise, just execute the command in the Terminal using the following syntax to set up a new password for the user.

$ sudo smbpasswd -a username

Restart Samba Service

Once you are done with all configurations and user setup, restart the Samba service by running the following command in Terminal:

$ sudo systemctl restart smbd.service

Connecting Samba share from Linux machine

Using command line

To connect samba share from the Linux command line, you will need to install the Samba client. It will help to connect samba shares from the command line.

Run the following command in the Terminal to install the Samba client:

$ sudo apt install smbclient

Once installed, connect to Samba share using the following syntax:

$ sudo smbclient //[IP_address or Host_name]/share_name –U samba_user

Where

  • [IP_address or Host_name] is the IP address or the hostname of the Samba server
  • [share_name] is the name of the Samba shared directory
  • [samba_user] is the name of the user who has access to the share

Once you enter the command in the terminal, it will ask you for the password. Type the password and hit enter after which you will see samba CLI. To view the supported commands on CLI, type help and hit enter.

Access Samba share using the GUI

To access Samba share via a graphical user interface, open File Manager. On the bottom of the File Manager window, you will see the Connect to server option. In the address bar, type the address of the Samba server in the following format and click Connect.

//[IP_address or Host_name]/share_name

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

When the following window appears, select the radio button Registered user and Enter username and password in their respective fileds. If you are in the WORKGROUP environment, leave the Domain field as default and click Connect.

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

Now you will be able to access shared files on the Samba server.

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

Method 2: Connecting Samba share from a Windows machine

In Windows OS, Run utility is mostly used to access shared files over the network. To open the Run utility, use Windows key R shortcut. When the utility opens, enter the Samba share address in the following format and click OK.

\[IP-address][share_name]

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

You will be prompted to provide the Samba user password. Type the password and click OK.

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

Now you will be able to access Samba shared files on your Windows machine.

How to Install and Configure Samba on Debian 10 Debian Desktop linux shell

In this article, we have learned how to install Samba on a Debian 10 system. We have also learned how to connect to the Samba server from Linux and Windows machines for accessing shared directories.