How to install and configure Samba on Debian

Samba is a powerful open source tool that allows Windows-like file and printer sharing on the network in Linux systems.

Samba is a powerful open source tool that allows Windows-like file and printer sharing on the network in Linux systems. It allows Linux and Windows computers to coexist and interact on the same network. Samba is installed on the Linux server where the shared files are located. 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 a Samba server on a Debian system. We will also learn how to access these shared files from a Linux or Windows machine.

Note : The article used Debian 11 to run the commands and processes mentioned in this article. However, the commands and procedures work almost the same in other Linux distributions.

Install Samba on Debian

Launch Terminal in your Debian operating system. Go to the Activities tab in the top left corner of the screen. Then in the search bar type the keyword terminal . When the search results appear, click the Terminal icon to open.

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

$ sudo apt install samba

How to install and configure Samba on Debian Picture 1How to install and configure Samba on Debian Picture 1

It may ask for confirmation by giving you the Y/n option . Press y to continue the installation process and Samba will be installed on your system.

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

Verify SAMBA installation

To verify the installation, check the status of the samba service 'nmbd'. This service starts automatically when installing Samba.

$ sudo systemctl status nmbd

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

How to install and configure Samba on Debian Picture 2How to install and configure Samba on Debian Picture 2

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

$ sudo systemctl start nmbd

Samba configuration

Once the Samba server installation is complete, it's time to configure it. The samba configuration file smb.conf is located in the /etc/samba directory . In this file, you specify the folder and printer you want to share along with their permissions and operating parameters. Samba reviews its configuration file after a certain period of time and updates any changes.

Follow the steps below to perform the configuration:

Step 1 : Create a folder to share files via Samba. This folder will hold files that need to be shared. Run the following command to create a new directory in the root directory.

$sudo mkdir /samba

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

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

This command will create a backup in the ~/Documents folder.

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

$ sudo nano /etc/samba/smb.conf

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

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

In there:

  1. [samba-share] = name of the samba share
  2. comment = brief description of the share
  3. Path = path of shared folder.
  4. Read-only = make the shared folder readable
  5. Browsable = whether to include shared content in the sharing list or not

 

How to install and configure Samba on Debian Picture 3How to install and configure Samba on Debian Picture 3

Once completed, press Ctrl + O and Ctrl + X at the same time to save and exit the file.

Set up user accounts

Now, let's set up a user account for samba. The Samba user must be a system user and therefore must exist in the /etc/password file. If the user doesn't exist yet, you need to create it first. If not, just execute the command in Terminal using the following syntax to set up a new password for the user.

$ sudo smbpasswd -a username

Restart the Samba service

Once you have completed all configuration and user setup, restart the Samba service by running the following command in Terminal:

$ sudo systemctl restart smbd.service

Connect Samba share from Linux machine using command line

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

Run the following command in Terminal to install Samba client:

$ sudo apt install smbclient

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

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

In there:

  1. [IP_address or Host_name] is the IP address or name of the Samba server
  2. [share_name] is the name of the Samba share folder
  3. [samba_user] is the name of the user who has access to the share

When you enter the command in the terminal, it will ask you for the password. Enter the password and press Enter then you will see the samba CLI. To see supported CLI commands, type help and press Enter .

Access the Samba share using the GUI

To access Samba shares via the graphical user interface, open File Manager. At the bottom of the File Manager window, you will see the Connect to server option . In the address bar, enter 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 Picture 4How to install and configure Samba on Debian Picture 4

When the following window appears, check Registered user , enter the username and password in the corresponding fields. If you are in a WORKGROUP environment, leave the Domain field as default and click Connect .

How to install and configure Samba on Debian Picture 5How to install and configure Samba on Debian Picture 5

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

How to install and configure Samba on Debian Picture 6How to install and configure Samba on Debian Picture 6

Connect to Samba share from Windows machine

In the Windows operating system, the Run utility is mainly used to access files shared over the network. To open the Run utility, use the keyboard shortcut Windows + R. 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 Picture 7How to install and configure Samba on Debian Picture 7

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

How to install and configure Samba on Debian Picture 8How to install and configure Samba on Debian Picture 8

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

How to install and configure Samba on Debian Picture 9How to install and configure Samba on Debian Picture 9

4 ★ | 1 Vote