Setup Raspberry Pi as File Server


A file server is a central server in a computer network that provides file systems or at least parts of a file system to connected clients. File servers therefore offer users a central storage place for files on internal data media, which is accessible to all authorized clients. Here, the server administrator defines strict rules regarding which users have which access rights: For instance, the configuration or file authorizations of the respective file system enable the admin to set which files can be seen and opened by a certain user or user group, and whether data can only be viewed or also added, edited, or deleted.

With file servers connected to the internet and configured properly, users cannot only access the files via the local network but also benefit from remote access. This enables files to be accessed and saved on the file server even when users are on the go. All modern operating systems such as Windows, Linux, or macOS can be used on a file server, although the devices available in the network need to be compatible with the operating system. But file servers are not only used for file storage and management. They are also often used as a repository for programs that have to be accessible to multiple network participants, and as a backup server.

The right hardware is the foundation for a reliable file server. Most importantly, of course, this includes the hard drive which needs to offer sufficient space for the files and necessary programs, as well as the respective operating system, and the software for using the clients. The server also needs enough working memory and processing power to process file and program accesses for various users as quickly and faultlessly as possible. Whether the hardware requirements can be fulfilled by a standard PC or whether a special server setup is required primarily depends on the number of users.

Special network protocols are responsible for communication between file servers and clients: While the SMB protocol (Server Message Block) <a href=”#anchor1″>[1]</a>developed by IBM is used in local networks with Windows and macOS devices, computers with Unix-like systems such as Linux distributions,  work with the NFS protocol (Network File System<a href=”#anchor2″>[2]</a>). To combine both protocol types in a single network, clients and file servers based on Unix/Linux must be accordingly equipped with software that implements the SMB protocol in these systems like the free software suite Samba.

The main functions of a file server are to enable multiple users to access the stored files and free storage space for the file repository.  These servers are popular as a central storage place for internal company files that are not only relevant for individual users. In many cases, companies  also use a file server as a download server connected to their own web offering. This way, they allow their customers or website visitors to download select content such as programs, drivers, updates, images, or videos with ease.

The second major application of file servers is data backups. Unlike when saving and jointly managing relevant files, this refers to the creation and maintenance of conventional backups of system or user files (or both) depending on the need. Storing these backup copies on a file server is both an easy and inexpensive alternative to having to plan and cover the necessary additional storage requirements on each individual client.  This works much like when file servers are used to host software and provide access for all authorized users. As the host terminal systems used in the past, computing power and storage capacity are conveniently outsourced, meaning the client devices only have to take on data entry and display.

Using a file server is worth considering for several reasons. First, there is the advantage of centrality which ensures each authorized network participant can access the stored files. This makes shared working possible on these files. Conflicts between different versions of a document can be  ruled out, as certain actions such as editing or deleting,  are blocked for other users as soon as you open a file. If users have to share the desired files on their own system instead, or transmit them using removable media, this would be more time-consuming and cumbersome. It would most likely result in different file versions.  Another key advantage of using file servers is that it relieves the strain on client resources. With the exception of personal documents, essentially all business files and backups can be stored on the file server, depending on how the company wishes to use the file repository. And with the right organization,  users automatically have a much better overview of the entire file inventory.

If the file server is configured for remote access over the internet, the files are also accessible on the go like an online storage service. But unlike a cloud solution, the company retains control of the files and their security at all times. This is a clear advantage over third-party solutions.  The advantages show how valuable a file server can be. However, many companies make the mistake of underestimating the work involved in setting up and managing such a server. Companies often do without advance planning. As a result, not only is the hardware stretched to its limits after a short amount of time, but also many of the benefits of a file server aren’t utilized. For example, if there is no clear principle for the assignment of rights, situations will likely arise in which users are unable to perform necessary actions. Problems may also occur when the directory and folder structure is unclear or if no folder structure exists at all.

If you’d like to use a file server, you should therefore consider these aspects from the very beginning, as well as a comprehensive security concept. In the case of the latter, this is important if the file server is also accessible over the internet. The installation and configuration of security software are just as critical as training the employees who access the file server. Only when they have been made aware of topics like cyber security and data protection can the configured protection mechanisms work as intended. This is also true when it comes to storing the files.  Clearly communicate where and how files should be saved on the file server to prevent a chaotic data situation from occurring in the first place.

We can set up a file server using a  Raspberry Pi and some cheap external hard drives that use little power and is always on.  The benefit of having an always-on network storage device is that it’s convenient to have your data always accessible to the computers both inside and outside your network.  A Raspberry Pi-based network storage device, uses about $5 worth of power per year<a href=”#anchor3″>[3]</a>.  Granted that a full fledged server is going to have more storage space and the capability to do more work such as transcoding a multi-terabyte video collection in a reasonable span of time.  But for most people,  the main purpose of having an always-on computer somewhere in the house is to serve as a file server and file backup repository. For such tasks the Raspberry Pi is more than powerful enough and will save you a chunk of change in power use.  This tutorial will assume that you already have your Raspberry Pi, got it powered up, hooked to a mouse and keyboard, and you’ve installed Raspbian on it.  IF not,  you can follow our tutorial here on how to <a href=”https://ames-pc.com/geek/blogs/blog.html?issue=1949″ target=”_blank”>install an OS on the Raspberry pi</a>.  If you just want a simple network attached drive, you’ll only need one hard drive. We highly recommend using at least two hard drives in order to allow for local (at the Raspberry Pi) data redundancy. For the purposes of this tutorial we’re using a matching pair of 2.5″ usb hard drives. 2.5″ usb drives are small and don’t require an external power source.  You can use any external hard drives you have on hand but you will need additional power plugs for the drives and will use more power.

Before we continue, there are a couple design choices in terms of how to configure our Raspberry Pi NAS.   We will be using NTFS-formatted hard disks because if the Raspberry Pi NAS fail for some reason or we want to quickly copy information over a USB 3.0 connection instead of via the network, having NTFS-formatted disks makes it simple to take the portable USB drives on the NAS build and plug them right into one of the many Windows machines.  We will be using Samba for our network shares, again because of the convenience of meshing the Raspberry Pi NAS with our predominantly Windows network.

The first thing to do is hook up the hard drives to the Raspberry Pi ( or the attached USB hub depending on your configuration and whether or not the hard drives are self-powered or externally powered ). Once the hard drives are attached and the Pi is powered up it’s time to get working.  Once the drives are connected, we will open up a terminal window and add in support to Rasbian for NTFS-formatted disks. To do so type the following command:

<pre>

  <code>

    sudo apt-get install ntfs-3g

  </code>

</pre>

It’ll take a minute or two for the packages to download, unpack, and install. Once the NTFS package is installed it’s time to look for the unmounted partitions of the attached external hard drives by typing <b>sudo fdisk -l</b>.  This will list all the disks attached to the Raspberry Pi.  The first disk /dev/mmcb1k0 is the SD card inside the Raspberry Pi that houses our installation of Raspbian. We’re going to leave that one completely alone.  The second disk, /dev/sda is our external hard drive.  Before we can mount the drives, we need to create a directory to mount the drives to. FTo keep things simple,  we’re going to make a directory called <b>data</b> for the drive by typing (b>sudo mkdir /home/data</b>.   After we created the directory,  we can mount the external drives with the following command: <b> sudo mount -t auto /dev/sda1 /home/data</b>.  At this point we have the external hard drive mounted to the data  directory.  Now we add in a specific directory to the drive to hold our shared folders by typing <b> sudo mkdir /home/data/share</b>.  

Now we can install Samba so we can access the storage from elsewhere on the network.   We do this by typing <b>sudo apt-get install samba samba-common-bin</b>.  When prompted to continue type Y and enter.  Once the Samba package finishes installing, it’s time to configure samba. Before we do anything else, make a backup copy of the Samba configuration file in case we need to revert to it by typing <b>sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak</b>.  This creates a backup of the configuration file with the filename smb.conf.bak and leaves it in the same directory as the original configuration file.  Now we can edit the samba file by typing in <b>sudo nano /etc/samba/smb.conf</b>.  This will open the nano text editor and allow us to make some simple changes.  Nano is completely keyboard controlled, use the arrow keys to move the cursor to the location you want to edit. As you click down through the configuration settings, you’ll see a few worth making note of or changing.  The first is the workgroup identifier, by default workgroup = WORKGROUP. If you’re using a different name for your home workgroup, go ahead and arrow over to change that now, otherwise leave it as the default.  Our next stop is to turn on user authentication for our samba storage, otherwise anyone with general access to our network like guest Wi-Fi users,  will have access.  Scroll down to where you see <b>security = user</b>.  Remove the <b># </b> symbol from the beginning of the line to enable username/password verification for the Samba shares.  Next, we will add an entirely new section to the configuration file. Scroll all the way down to the very bottom of the file and enter the following text:

<pre>

  <code>

    [share]

    comment = Data Folder

    path = /home/data/share

    valid users = @users

    force group = users

    create mask = 0660

    directory mask = 0771

    read only = no

  </code>

</pre>

Whatever you put in the brackets in the top line is going to be the name of the folder as it appears on the network share. If you want another name other than “share”, now is the time to edit it.

Press <b>CTRL+X</b> to exit, press Y when asked if you want to keep changes and overwrite the existing configuration file. When back at the command prompt type in the following to restart samba: <b>sudo /etc/init.d/samba restart</b>.

Now we can add in a user that can access the Pi’s samba shares.  We create users by typing in <b>sudo useradd USER -m -G users</b> replacing user with a user name.  Next,  we will create a password for the new user by typing in <b>sudo passwd USER</b>.  You’ll be prompted to type in the password twice to confirm.  After confirming the password, it’s time to add USER as a legitimate Samba user by typing in <b>sudo smbpasswd -a USER</b>.  Enter the password for the USER account when prompted. Once you have created the user account and password you do not need to restart the Samba daemon again since we already instructed it to be on the lookout for authenticated users. We can now hop onto any Samba-capable machine on our network and test connectivity to the network share.

<p id=”anchor1″>[1]<a href=”https://www.technipages.com/definition/server-message-block-smb-protocol” target=”_blank”>  https://www.technipages.com/definition/server-message-block-smb-protocol</a>    “Server Message Block (SMB) Protocol”</p>

<p id=”anchor2″>[2]<a href=”https://www.ibm.com/docs/en/aix/7.1?topic=management-network-file-system” target=”_blank”>  https://www.ibm.com/docs/en/aix/7.1?topic=management-network-file-system</a>    “Network File System”</p>

<p id=”anchor3″>[3]<a href=”https://picockpit.com/raspberry-pi/how-much-does-power-usage-cost-for-the-pi-4/” target=”_blank”>  https://picockpit.com/raspberry-pi/how-much-does-power-usage-cost-for-the-pi-4/

</a>    “How much does power usage cost for the Pi 4?”</p>