• Home
  • |
  • Blog
  • |
  • The Ultimate Guide To Build A Personal Cross-Platform File Server On Raspberry Pi!
The ultimate guide to build a personal cross-platform file server on Raspberry Pi!

Raspberry is such a powerful tiny computer you can use this as a tool for pretty much anything. Our focus in this article is to know how to build a personal cross-platform file server on Raspberry Pi.  We are sure that after reading this article you will be in a position to set up your Raspberry Pi as a fully functional file server on your home network. 

There are multiple third-party tools are in the market which allows you to set up your own file server. Some of them are free and some may come for an extra cost.  However, our goal is to let you know how to build a working file server by leveraging the service of simple SMB/CIFS protocols.  We are using Samba to implement SMB/CIFS services to share the storage across the network. Along with this, we thought it’s good to share some information about file permissions on Linux. Let’s make a checklist of components we need to set up a file server.

What Is Required To Build A File Server On A Raspberry Pi?

  1. A running Raspberry Pi with Raspberry PI OS, Samba and a couple of packages installed on it. Please check out our posts “How to set up a Raspberry Pi for the first time?” and “Five easiest ways to connect Raspberry Pi remotely in 2021:” if you are working on the Pi for the first time.
  2. Your choice of clean formatted and partitioned storage drives to connect to Pi. Please check out our post “How to Partition and Format the Hard Drives on Raspberry Pi?” to know more about adding a hard drive to Raspberry Pi.

What is Samba?

As the front page at samba.org says: Samba is a software package that gives network administrator, flexibility and freedom in terms of setup, configuration, and choice of systems and equipment. Because of all that it offers, Samba has grown in popularity and continues to thrive every year since its release in 1992.

Samba is software used to implement Server Message Block (SMB) protocol. It’s used to share files over the network. It is also referred to as Common Internet File System, in short CIFS. If you ask what platforms support this protocol. The answer is pretty much all. It supports Windows, Linux, and Mac. What support you need else! With a couple of additional packages and few configurations, you can build a personal cross-platform file sharing server on Raspberry Pi at your home. Which provides a central storage and capable to share files with other computers, smart TV, smartphone, and other smart devices.

How To Install Samba On Raspberry Pi?

As Samba is available on the apt packages, you can directly install the package using apt-get. There are two different packages to install, so you can install both of them in a single command.

1. Install samba on Raspberry Pi.

$ sudo apt-get install samba samba-common-bin

Type ‘y’ and let the installation to continue.

2. You may see this configuration wizard right before the installation. Choose ‘Yes’ if you already have a router which is serving as a DHCP server and disseminating IP addresses. Say ‘no’ if this is the only server running in your network. We are going to select ‘yes’ as we do have a router in our network.

When the Samba installation gets completed. You will be ready to start setting up shares. Let’s assume we have created two partitions on our drive one partition is created using NTFS and the second is created using EXT4 file system. And, we have mounted both the partitions under /mnt/data-ntfs and /mnt/data-ext4 paths respectively. If you do ls -l /mnt this is how you should see.  There is another dedicated post on how to partitions the drive “How to Partition and Format the Hard Drives on Raspberry Pi?”. We recommend reading that post before you proceed.

File System Permissions On Linux:

Although, file permissions on Linux is a different topic, however, we would like to give you some heads up on this as it is required to understand if you are dealing with file sharing on Linux. In essence, there are three types of permission in Linux, Read, Write, and Execute. All three permission are applied to three types of user entities, Users, Groups, and Others.

  1. User: A user who created the file. You can call them the owner of the file. Who has read, write and execute permission on their created files by default.
  2. group: In Linux, all files and directories will also have a group, a collection of users belong to the group.
  3. Others:  Finally, everyone else.

Now, pay some attention to the first few characters on both lines in the above-shown picture. They are the set of 10 characters segregated into four subsets, They specify the permissions set on their files and directories.

  1. 1st char: ‘d’ represents it’s a directory. In case of any other files you may see ‘-‘.
  2. 2nd, 3rd, 4th chars: Represents the Read ‘r’, Write ‘w’, and Execute ‘x’ permissions for the ‘User’.
  3. 5th, 6th, 7th chars: Represents the Read ‘r’, Write ‘w’, and Execute ‘x’ permissions for the ‘Group’.
  4. 8th, 9th, 10th, char: Represents the Read ‘r’, Write ‘w’, and Execute ‘x’ permissions for the ‘Others’.

In the above picture, 1st char of both files are ‘d’, it’s a directory. If you read the rest of the characters you will come to know that the ext4 partition has all ‘rwx’ remissions for the ‘User’, only ‘r-x’ read and execute permissions for ‘Group’ and ‘Others’. Similarly, if you read the remaining nine characters of the NTFS partition, all type of users have all permission on it. This shows that the Linux system manages the permissions differently on the different type of file system. If you see NTFS permissions here, everyone is allowed to do everything on the NTFS file system. It is normal because NTFS security doesn’t work in the same way as ext4 works. Linux can’t enforce its rules on the NTFS file system. If you want granular access controls, NTFS may not be the right choice for you. We recommend creating public directories and assign permissions to them rather than managing the permissions at the level of the partition. 

You can manipulate the permission by using ‘chmod‘ command.  To grant the missing write permissions on the ext4 public directory, type the following command.

$ sudo chmod go+w data-ext4/public

Here ‘go’ stands for Group and Other users, ‘+’ represents adding permissions, ‘w’ stands for Write permission. Please refer to the chmod and chown commands for more information https://www.computerhope.com/unix/uchmod.htm

How To Configure Samba To Share Directories On Raspberry Pi?

How to configure Samba on Raspberry Pi?

  1. $ sudo nano /etc/samba/smb.conf

    Let’s back to our original topic. Share the public directories created on both partitions by configuring smb.conf file.  Open the file using your choice of text editor. We are using nano text editor for demonstration purpose.edit smb configurations

  2. A small Note from smb.conf:

    Workgroup setting is important when you want to access the shared files from a Windows machine.  Change the correct workgroup under the global settings if your windows workgroup is different than the default. Or, leave as default.smb.conf file

  3. Add min protocol = SMB2 this is because, smbv2 is around for a long time and older versions of windows still supports v2 protocol.

    set SMB version in SMB configurations

  4. Create file shares in SMB config file.

    Go the the bottom of the file and create file shares by appending these lines to the file. create mask and directory mask is not required in case of ntfs as it doesn’t matter even if you add them because Linux system can’t enforce any permission rules on ntfs file systems. Please refer the Samba manual for more information on this.
    [public-ext4]
    path = /mnt/data-ext4/public
    public = yes
    writeable = yes
    create mask = 777
    directory mask = 777


    [public-ntfs]
    path = /mnt/data-ntfs/public
    public = yes
    writeable = yesCreate file shares in SMB config file

That’s it. Your Samba service should pickup the changes by it’s own and sharing should be running already. Try rebooting the service if it didn’t.

Few tips:

Do this if you see any problem.

  1. Update the OS and its registry: $ sudo apt update && apt upgrade
  2. Install these packages which help in working with multiple file systems: $ sudo apt install exfat-utils exfat-fuse ntfs-3g
  3. You can secure your sharing by adding a user account to smb.conf file. to add user account, open the file /etc/samba/smb.conf in any text editor and add the ‘valid user = user1’ line.
  4. If you can’t connect your Pi with its name, try this. Add ‘wins support = yes‘ under the global settings. “This is optional”.

This is how you can build a personal cross-platform file server on Raspberry Pi.

Thank you for reading this article. Please visit the below links to read more such interesting articles. Please leave your comments here below and let us know your feedback. This helps us to bring more such articles.

About the author

Arun KL

To know more about me. Follow me on LinkedIn Hi All, I am Arun KL, an IT Security Professional. Founder of “thesecmaster.com”. Enthusiast, Security Blogger, Technical Writer, Editor, Author at TheSecMaster. To know more about me. Follow me on LinkedIn

Leave a Reply

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

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Learn Something New with Free Email subscription

Email is also one of the ways to be in touch with us. Our free subscription plan offers you to receive post updates straight to your inbox.