Introduction
In the previous article, I talked about setting up a shareable drive in Linux with NFS. Although while researching, I did check out setting up a shareable drive with SMB using Samba.
While I am sticking with NFS for my use case since I am communicating between Linux servers, It might be useful to know how to setup drive with SMB which can be accessed from a Windows system as well.
What is SMB?
SMB stands for Server Message Block. It is a network protocol that allows users to share files, printers, and other information between computers. It is also known as Common Internet File System (CIFS).
If you want to have a shareable drive which communicates with Windows systems, you will need to setup a shareable drive with SMB.
What is Samba?
Samba ↗️ is an open-source implementation of the SMB protocol. It allows Linux systems to communicate with Windows systems using SMB protocol.
We will learn how to set it up correctly and make a drive network shareable.
Let’s get started
Once again we need at least two machines to setup a shareable drive. One will be the server and the other will be the client.
Server
First, let’s setup the server machine. I am using Debian 12 but the commands should be similar for Ubuntu and other Debian based distros (or replace some installation commands with your distro’s package manager).
Let’s install Samba on the server machine.
Once samba is installed, we will add ourself as a user to samba.
Replace <username>
with your username.
Now we will create a directory which we will share with the client machine.
Next, we will edit the samba configuration file.
Go to the very bottom of the file and add the following lines.
What this is doing is creating a shareable directory called smb_share
in /media
directory. It is also allowing the user <username>
to access it.
We have also marked this as read only = no
, which means that the user can read and write to this directory which is most likely your use case as well but feel free to update any values as per your need.
You can read more about the configurations on the available man page ↗️
Once you are done, save and exit the file.
Next, we will restart the samba service.
That’s it from the server configuration point of view, let’s move to the client setup now.
Client
Now, we would pretty much do the same thing as we did in the previous blog with few additional steps.
First, we will save our samba credentials in a file. This is required because when we try to connect to the server, it will ask for the password and we don’t want to enter it every time.
Replace <username>
and <password>
with your username and password that you added during the samba setup on the server.
Next, we will create a directory where we will mount the shareable drive.
Now, we will mount the shareable drive.
Replace 192.168.0.100
with your samba server IP address.
This will mount the shareable drive on the client machine. You can now access it from the /mnt/smb_share
directory.
Auto Mounting Drive on Boot
If you want to mount the drive automatically on boot, you can add the following line to your /etc/fstab
file.
Once again, replace 192.168.0.100
with your IP address.
Use the mount -a
command to check if the drive is mounted correctly.
And you can again verify if it is mounted correctly or not by using mount
and grep
commands.
Few Gotchas
In this section, I will just list down few things that I encountered while setting up the shareable drive.
Firewall
If you are using a firewall, you will need to allow the samba port. The default port for samba is 445
.
If you are using ufw
firewall, you can directly use the samba
rule and add it to the allow list.
Debugging Mounting Issues
If for some reason you are not able to mount the drive, you can use the dmesg
command to debug the issue.
I have found this very helpful in debugging the mounting issues. Looking for the messages related to the mount operation and in case of any errors it will most likely tell you what is wrong along with the error code.
Use that to find the relevant solution to your problem.
Conclusion
In this article, we learned how to setup a shareable drive with SMB using Samba. We also learned how to mount the drive on the client machine and how to auto mount it on boot.
While I am sticking with NFS for my use case, I hope this article was helpful to you in setting up a shareable drive with SMB.
I hope you found this article useful. If you have any questions or feedback, please feel free to reach out to me on X / Twitter ↗️.
Until next time đź‘‹.