The File Server – Part 4 SAMBA

Published on October 30, 2021 at 11:32 am by LEW

Introduction

We are now going to look at setting up the classic Windows style remote drive on a Debian server. Most people who use the Windows Operating System (OS) at work are familiar with this type of remote drive. It shows up in the file browser with its own drive letter. And in many ways it acts like the drive in your local computer.

Note, we are setting this server up to use the home directories of the users, rather than a common shared directory. Please review the section of the FTP post about partitioning the drive with a separate /home partition.

SAMBA Software

We will be using the SAMBA software to create a SMB share on our Debian Server. SAMBA was created back in 1992, and emulates the Windows SMB protocol. It can act as a file server or Domain Controller. As of version 4 it also supports Active Directory.

SAMBA runs on most *nix like operating systems. For example;  Linux, Unix, Solaris, MacOS, and BSD to name a few.

Setting up the IP Address

As per our previous post, SAMBA works best with a static IP Address. Please refer to the previous post for more details. For quick reference , something similar to the below should appear in the Debian /etc/network/interfaces file.

Auto enp0s3

iface enp0s3 inet static

address 192.168.2.3

netmask 255.255.255.0

gateway 192.168.2.1

Once set, the network can be restarted with the following command.

systemctl restart networking

The changes can be verified with the following command.

ip a

Installation of SAMBA

We will use the standard apt command to install the SAMBA package.

apt install samba

If you also want to run headless, you can install the following package also.

apt install openssh-server

This reminds me that I should do a write up on openssh sometime soon. Though in most cases it just works. We will be revisiting openssh when we talk about SFTP. You will need a ssh client for your computer. I suggest using PuTTY, a free and easy to use ssh client.

Testing if SAMBA is Running

To test the installation of SAMBA, we will use the systemd command systemctl. The following will show if SAMBA is running in the background.

systemctl status nmbd

If the program daemon is not running in the background after a server restart, then we will need to use the following.

systemctl enable nmbd

The SAMBA daemon can also be controlled with the following additional commands.

systemctl start nmbd

systemctl stop nmbd

systemctl restart nmbd

SAMBA Configuration

On Debian, the SAMBA global configuration file is located at “/etc/samba/smb.conf”. The first thing you will want to do is make a copy of the file, just in case of problems.

The smb.conf file in Debian is usable out of the box. There are only a few changes that we may want to make. So open the file in your favorite text editor.

In the [global] section you may want to change the Workgroup name from its default to something more in line with your local setup.

Workgroup = WORKGROUP

Further down in the [homes] section you may want to allow files to be written to the server. There are two values you will need to change for this.

read only = no

permission 0775

SAMBA User

You must add a Samba user, a step I forget some times. Please note the SAMBA user here must exist on the server. You can use the adduser command to create a new user with home their own directory. To add a SAMBA user use the following command.

smbpasswd -a user

You will need to enter and confirm a password for this SAMBA user.

Connecting to the SMB Share

In your file browser, look for an option about Adding a Network Location. From there type in the IP address of your server and the user name. This may vary from OS to OS. For example user John on our server at 192.168.1.10 under Windows OS would be entered like this.

\\192.168.1.10\john

If everything is working you should get a pop up asking for user name and password.

If you have issues connecting, you will want to check any firewalls or anti virus programs. SMB usually uses port 445.

Conclusion

After completing the steps in this post you should have a remote SMB file share on your server. You should be able to connect to it from a file manager on your main computer, and transfer data back and forth.

File Server Part 1 Some Basics

File Server Part 2 Design

File Server Part 3 FTP

File Server Part 4 SAMBA

Add New Comment

Your email address will not be published. Required fields are marked *