Deploying a Network Share Drive Using Samba


In my last blog post I went over the deployment and configuration of a virtual server. I recently started hosting a network share drive on this server using Samba. It was simple and straightforward to deploy, and it has also made managing files across devices on my network much simpler. Please join me as I show the process of deploying a share drive using Samba.

What is Samba and Why Use it:

Samba is a suite of free and open-source software that facilitates the sharing of resources, such as files and printers, across a network. It works with Windows, Mac and Linux, making it perfect for my network as I actively use all three operating systems.

Installation:

To Install samba, first make sure the system is up to date. My system’s operating system is Ubuntu Server, so to ensure that my system is up to date, I need to run the following command:

After I ensure my system is up to date, I am ready to install samba. To install samba simply run the following command:

After running the above command, I verify that I have successfully installed samba. To verify my installation was successful I run the following command:

The output I received was “usr/sbin/samba” showing me the path to samba which will be utilized when it is running. Had there been nothing displayed, I would have known that samba had not been installed, and I would have begun troubleshooting what had gone wrong.

Creating Directory to be Shared:

Now that I have samba installed, I can create the directory which will become my Share Drive. As far as where to put my directory, I went ahead and used my home directory. To create this directory I simply enter the command: 

At this point I have created the directory which will become my share drive. Right now It looks like a normal directory because it is. In the next step, I’ll configure samba to start sharing this directory across my network.

Configuring File Share

To configure samba to share the previously made directory over the network, I need to edit the samba config file. This file is located at:

There are a few different ways to edit this file such as command line text editors, redirecting output, and even some more advanced Unix/Linux commands like sed. The simplest option is to just use a command line text editor. Personally I like using VIM so I simply ran the command:

At this point I have the file open in VIM. I can edit the file by pressing the “i” key, and entering insert mode.  I then scroll to the bottom of the file and add the following lines to the file:

After I enter these lines I can save and quit VIM. To do this I simply press the escape key to exit insert mode. Then I type:

This stands for write and quit respectively. When I press enter, VIM will write the changes I’ve made, then quit the program.

Starting Samba:

At this point, I have a directory made which will be shared across my network. I have also configured samba to share this directory across my network. My next step is to start samba, and configure it to start at boot. To start samba I run the following command:

Now that samba is started, I want to make sure that samba will automatically restart if the server reboots. To make sure that samba always starts when the server boots up I will run the following command: 

Configuring the Uncomplicated Firewall (ufw):

At this point samba is up and running, but I still have a problem. Ubuntu uses the uncomplicated firewall (ufw). The ufw does a good job of keeping our system secure. However it will also prevent other devices from accessing the directory that Samba is trying to share with them. To write a new ufw rule allowing Samba, run the following command:

Setting up Samba Password:

Lastly I need to add a username and password to my share drive. To add a username and password to my share drive, I will enter the following command:

After running this command I will be prompted to enter a password twice. After entering the password I have completed setting up my samba share drive. It is important to note that the username used with samba needs to match a user on the system. If there were no “ian” user on my system, then the above command would fail.

Connecting devices to share drive:

I have now set up samba, created a firewall rule to allow samba, and set up the credentials to access my share drive. At this point all that’s left to do is connect devices to my share drive. Every operating system will have its own way to connect to a share drive. For this post I will simply go over connecting a Windows computer to my share drive. To connect my Windows computer to my share drive I start by opening the file explorer. After opening the file explorer, in the address bar I enter the following address:

I will then be prompted for a username and password. After entering my credentials, I am connected to my newly made samba share drive.

Conclusion:

This project was fun and easy. I really liked how it was immediately useful. The same day that I completed this project I had to run a major update on one of my computers. I was able to backup all my files to the newly created samba share drive in a matter of seconds. This saved me from having to dig around my office and find a thumb drive and manually back up my computer. I hope you enjoyed following along, and I look forward to sharing more as I keep learning and growing my skill set.

Special thanks to my father in law who was kind enough to proof read my writing. He can be found here.


,