Four simple steps to set up a Linux server as your home file storage

It has been a long time since my last post – two whole years, in fact! Time flies, doesn’t it? And now I’m back with an exciting new project that I’ve been eager to share: setting up a home file server on a Linux machine.

With the rapid growth of personal digital content and the increasing number of devices we use daily, managing and accessing our files can become quite the challenge. A home file server is a perfect solution to keep all your files in one centralized location, accessible from all your devices. You can use it to back up your important data, share your documents, and more.

In this blog post, I’m trying to provide a brief guide on setting up a home file server using a Linux machine. Why Linux? It’s cheaper and more flexible than NAS, and even software like OpenMediaVault does not provide flexibility of a Linux machine. But you have to take responsibility for server set up, securing and maintenance. So, if that does not scare you – let’s dive in!

Prerequisites

  • Hardware. I started with a pretty old HP desktop with AMD CPU and 8GB of RAM. That seemed to be enough but several times the server froze and only restarting it brought it back to working state. Digging into Linux help articles and running system information tools on the server proved that happened because of lack of RAM. So, 16GB or even 32GB if you plan to run additional services on the server is better.
  • Make sure you have at least 1 Gigabit network card in the server and all your networking equipment supports that speed or even faster. Don’t use Wi-Fi unless it’s Wi-Fi6.
  • Hard drives. For me it’s still a moot point. I chose Samsung 870 EVO SSDs which seem to be pretty reliable, but I don’t argue with those who say that HDD is a better option for servers and backups. The only thing I’m sure about is that each technology (HDD and SSD) has its strengths and weaknesses.
  • A Linux distro. I’m using Ubuntu Server 22. I was considering Debian 11 as an option but since I had previous experience with Ubuntu, I preferred to use something I have knowledge about.
  • A stable internet connection.
  • Basic knowledge of Linux command line and file management.

Step 1: Install the system

Maybe the most important decision during the installation process is whether you want to encrypt your data. My choice was to encrypt everything: system and home partitions and data storage drive. The only drawback I see here is when I restart the server I need a monitor and a KB to enter passwords. But security is more important.

Step 2. Set up the server

Now that the server is installed and running you can install and set up all the services like Samba and whatever you plan to run on the server. What I’d recommend setting up besides that includes the following.

Set up SSH and restrict root from logging in via SSH.

Create a firewall rule allowing SSH connections and start the firewall.

To protect the server from brute-force attacks I use fail2ban. You may want to set it up as well. Run sudo apt-get install fail2ban to install it (it also needs some basic configuration).

Mount data drives (you are using a separate drive for data storage, right?), set up file system permissions and folders’ owners.

If you use SSDs in your server’s hardware configuration, then I’d recommend to set up TRIM to prolong their life and improve performance.

Step 3. Install and set up Samba

Install Samba and create a Samba user. Give preference to a user with no local login allowed and no home folder.

Edit /etc/samba/smb.conf and create shares.

Allow Samba connections through the firewall.

Step 4. Install and configure backing up

Every server must have a back up solution. Your home file server is not an exception. There are several options how to back up your server, I would mention two of them: making backups to something installed at your home like NAS or external USB drive and cloud storage. I prefer the second option because it physically keeps a copy of all my files at another location which is important in case of, for example, natural disaster. If your files are super important you can combine these two options. Just remember to keep your external USB drive disconnected from the server and connect it only to make a copy of your data. It’s up to you how often to run the back up process, I set it up to run once a day.

What’s next?

Now that you have your Linux server running, you can add other server roles, if needed, such as FTP, print server, or host different VMs. Don’t forget to take care about making all your network ready to provide 24/7 connection to the server. That means all your network equipment should be connected to power outlets using UPSs (which is a must have for the server). Don’t forget to log into the server regularly to install updates – that’s very important for keeping it secure.