Skip to main content

How to set up Samba file sharing on a headless Linux Server


This guide assumes that you have a headless server up and running, if not refer to the following articles to set up your headless server.
  • What hardware to choose for a headless Linux Server?
  • What Linux OS to choose for a headless Linux Server?
  • Step by Step guide to set up Ubuntu Server LTS
I'd suggest you go with the latest Ubuntu Server LTS edition or the latest Debian release as they run pretty stable and have good online communities around them.
This guide was written with Ubuntu Server16.04 LTS as reference. 


1) Usually while installing the server editions of linux you have the option to install samba service or the samba file server. You can check whether samba(smb for short) is installed on your server with these commands.

 samba --version





You should see the proper version number as shown above.

You can also check if samba is installed by checking if samba config folder exists,you can do that by running the below command.  

cd /etc/samba 


 2) If you already have samba installed, you can skip to step 3. You can install samba by running this command.

sudo apt-get install samba


3) Next create a directory/folder to be shared on the network using the mkdir command.

You can skip this step if you want to share an existing folder.







I created a folder called  'share' in my home folder.
 

If you want to share a different partition or a different storage device, you'll have to mount it inside the share folder, you can manually mount it every time the OS boots up but creating an fstab entry will automatically mount it for you.
You can check out this article to know more about adding entries to fstab.


4)(Optional but recommended) Create a new user using the following command

This will be the dedicated user to access your file share, having different users will allow you to set access control over your file share. You can create a user with read-only permissions and control what parts of the share they can view,access and modify.
You can create sub-folders within the main share directory and assign different folders to different users and varying access controls and allow only the admin to manage the whole share(more on this later)

sudo useradd -M shareUser

-M attribute creates the user without the home directory.

Since, this user is only needed for access control and authentication it does not need a home folder.

5) Create a new SMB password for your user, this password will be necessary to access the share.

sudo smbpasswd -a shareUser






Make sure that the smb password is not same as the linux account password.

It is a good idea to block ssh login's for the shareUsers if you use the same password.

6)Open the smb.conf file by running the following command.


sudo nano /etc/samba/smb.conf

smb.conf is where you configure all your shares and manage your shares.

Add the following lines to the end of the file.













The name in [] has to be the name of your shared folder, path points to your shared folder(existing or newly created). Remaining parameters are quite self explanatory.

Make sure you have proper spacing between the attribute and its value as shown(one space before and after the '=').

Save the file and exit.

There are many more parameters you can configure based on your specific needs, but these are the basic set of parameters which are usually defined.

7) Restart the smb service by using one of the following commands.

sudo service smbd restart

or

sudo systemctl restart smbd


This will restart the samba service and your configurations should be set up.



Now you should be able to access your share from a different machine, windows or unix based systems.
Most of the linux distros come with samba client pre-installed and you can set up the share in the network section of your file explorer.

I use VLC on smart TV's to access my shares and playback media content and Solid Explorer on my phone for backing up phone data.

 

Comments

Popular posts from this blog

Why Create? #BeyondTheEdge #AsusIndia

Why Create? Creativity can be very positive That is a very interesting question. Before I get into my thoughts about creating and how ASUS is breathing fresh air into the otherwise stale laptop market in India, I just want to talk about my journey through this process. The process of writing about "why create". The whole process of writing this article has been a journey of learning new things about myself. I'm glad that I took up the challenge of trying to collect my thoughts and bring them into a form which means something important to me. I'm an ever-cliched engineering student studying in one of the famous colleges in the city. Tech-head, curious-owl, an overthinking music-head are couple other terms with which I would describe myself. The world is big, yet a small place filled with lots of questions.When asked about how to be successful in life, I have often heard the phrase "fall in love with the process" by people like Gary Vaynerc...

First about myself!!

Welcome to the blog of mine .My name is Chinmay and I am a person who goes crazy when new things(i mean mobiles,computer hardware,all the consumer electronic goods) come out  .I have been following the PC hardware market from many years .I want to share all my knowledge about computers and the electronic goods.I can give good suggestions on custom PC config,mobiles etc.                                     From now on I will be writing reviews,posting videos of unboxings of various things I buy and I get to review.I have already posted few videos of unboxings on my YouTube channel.I got very interested in PC hardware after I started watching videos of Linus Sebastian from Canada.He is a great guy and does great reviews.I was inspired by him and suggest everyone to watch his videos.                             ...