How to turn a Raspberry Pi into a file server?

1. Install Raspbian OS: First, you will need to install the Raspbian operating system on your Raspberry Pi. This can be done by downloading the Raspbian image from the official Raspberry Pi website and writing it to an SD card.

2. Configure Network Settings: Once the Raspbian OS is installed, you will need to configure the network settings. This can be done by editing the /etc/network/interfaces file.

3. Install Samba: Samba is a software package that allows you to share files over a network. To install Samba, open a terminal window and type in the following command: sudo apt-get install samba samba-common-bin.

4. Configure Samba: Once Samba is installed, you will need to configure it. This can be done by editing the /etc/samba/smb.conf file.

5. Create a Shared Folder: Now you will need to create a shared folder. This can be done by creating a new folder in the /home/pi directory and setting the permissions to allow read/write access.

6. Restart Samba: Finally, you will need to restart Samba. This can be done by typing the following command into a terminal window: sudo /etc/init.d/samba restart.

Your Raspberry Pi is now ready to be used as a file server.

Have you always dreamed of having a family NAS with your backups and movies? But you do not necessarily have the budget for that?
Raspberry Pi allows you to do that at a lower cost, and I will give you all the details in this post
.

How to turn your Raspberry Pi into a file server?
To use a Raspberry Pi as a file server, a service, named Samba is available.
Once installed and configured correctly, files on the Raspberry Pi can be shared with everyone on the same network.

We will now see in detail a typical installation, i.e., how to install Samba on Raspberry Pi OS and then configure it.
And then we’ll see how to enable DLNA to make your Raspberry Pi accessible from your TV.
I will also give you some tips to improve this installation
.

You can use any storage you want to try this tutorial, but if you really want to build a reliable NAS with a Raspberry Pi, I recommend looking for something like this HAT on Amazon, to connect SATA drives to it, and stack them, so that you can have redundancy.

Why use a Raspberry Pi as a file server?

File server usage

A file server is used to store and share files on the local network.
This server allows you, for example, to create automatic backups of your computer on this server
.

You can also store files that take up space on your computer but are not critical:
– movies
– software
– ISO files

Raspberry Pi advantages

A standard NAS server, will cost over $300 for the entry level, make noise and consume a lot of electricity.

A Raspberry Pi will cost you less than $50 and waste almost no power.
You will eventually need to add the price of a hard drive if you need a lot of space, but it is reasonable.
A 2TB USB drive on it and you are ready to go (check this one on Amazon, the best value for money).

This allows you to add a small backup storage server at a lower cost while learning how it works.

Add disk space to Raspberry Pi

If you follow this guide only for testing, you do not necessarily need to read this paragraph.
It concerns people who do not have enough space on their SD card and who want to have more free disk space.

A larger SD card

The first possibility is to use a larger capacity SD card.

You may have an SD card of 8 or 16 GB at the moment, so it’s going to be a bit limited.
But there are SD cards that go up to 1 TB and for a reasonable price (this one for example).
It may be worthwhile to buy a larger SD card before following this tutorial.

SanDisk offers SD card up to 1TB now!

Feel free to check my resources page if you want to know which SD card I recommend.

If you choose this, there is nothing else to do technically than replacing the SD card in the drive. And then resume the rest of this post.

USB hard drive

Another possibility is to connect an external USB drive to your Raspberry Pi.

With the 2.5″ format you should be able to find disks up to at least 2TB, which starts to be a better configuration for file sharing (I’m using this one for example).
It also gives you the advantage of being able to bring it with you even if you are not taking your Raspberry Pi.
And so to read the content on any computer.

Most of the time your hard drive will be recognized and mounted directly by Raspberry Pi OS.
A mount point will be created in /media/pi/NAME.
Where NAME depends on the name of your hard drive.

If you have any issues, I recommend formatting your disk in a Linux file format (EXT4 for example) and to try again.
The fdisk and mount commands could also serve you in the worst cases.
I explain everything here if you need some help about formatting and mounting a USB drive on Raspberry Pi.

A SATA hard drive?

If you want something professional, you can add a card to connect SATA hard drives to your Raspberry Pi.
This card will allow you to get closer to a classic NAS with faster, better-integrated disks and the ability to manage security with software RAID.

This implementation is another project, so I let you do your research and come back here once your disks are functional ?

Install Raspberry Pi OS

So we have our prerequisites completed:
– an SD card
– possibly additional storage

So let’s move on to the installation of Raspberry Pi OS which will be the basis of our file server.

Note: If you want to see all these steps in action, I have a video lesson available for the community members. You can join here and watch it directly if you are interested (with 10+ other lessons for Raspberry Pi and many other benefits).

Download Raspberry Pi OS

First, you will have to download the latest version of Raspberry Pi OS from the official website.

If your goal is only to have a file server, the lite version is enough, and you’ll save some disk space and CPU/ram.
Anyway we will do all the rest of this tutorial with SSH, so it doesn’t change.

Download the image and continue

Flash an SD Card with Raspberry Pi OS

I recommend using Etcher.
If you have not installed it yet, get it from the official website.
It’s a tool that allows you to flash an SD card easily on Linux, Mac, or Windows.

  • Start Etcher
  • Select the location of the Raspberry Pi OS image
  • Choose your SD card
  • Click on Flash
etcher menu

Once the SD card is ready, eject it and insert in your Raspberry Pi.

First Boot

The installation is automatic, you have to start your Raspberry Pi, and Raspberry Pi OS will start.

If you choose the Pi Desktop, a welcome wizard will show up:

  • Choose your language preferences
  • Change the default password
  • Connect to the Wi-Fi if necessary
  • Accept system updates
  • Reboot the Raspberry Pi

If everything worked fine, move on.
Otherwise, it will be necessary at least to succeed to connect the network and to change the password (the following paragraph can help you).

If you have the Lite version, you have to do the same thing within raspi-config.
I explain everything here if you need some help.

Enable SSH

SSH is a secure remote connection protocol, which allows you to launch commands from another computer on the network.

By default, the service is not started automatically on Raspberry Pi.
So we will enable SSH and connect to it before continuing.

To enable SSH, open a terminal and type this command:
sudo service ssh start

Once SSH is installed connect to it (ssh pi@IP).
If this is not easy for you, take a look at this article that will guide you through this.

Install the file server

Now that Raspberry Pi OS is ready let’s get to the goal of this tutorial: create a file share.

Organization of the file system

Depending on what you initially chose as a storage type, the paths will change a little later.
So I’m going to assume that our available storage space is in /media/share
Replace this with the right folder you have created.

If you have chosen to share your files directly on the SD card, create a new folder of your choice (/media/share for example):
sudo mkdir /media/share

In other cases, you should create a mount point in /media/pi/share or something like that.
More information here on how to mount USB drives on Raspberry Pi.

Install Samba

Start by checking for updates:
sudo apt-get update
sudo apt-get upgrade

Then install samba:
sudo apt-get install samba

Once samba installed you should be able to access the Raspberry Pi with the file explorer:

Replace X.X.X.X with the IP address of the Raspberry Pi.

But for now, we do not see a shared folder, and we can’t create files.
Let’s see how to fix this.

Configure Samba for a guest share

Samba is now available, let’s go to the configuration.
The configuration will depend on what you want to do, but I’ll explain how to create a basic sharing:

  • Give all permissions to the folder
    sudo chmod 777 /media/share
  • Edit the /etc/samba/smb.conf file
    sudo nano /etc/samba/smb.conf
  • Add these lines at the end of the file
    [SharePi]
    comment = RaspberryPi
    public = yes
    writeable = yes
    browsable = yes
    path = /media/share
    create mask = 0777
    directory mask = 0777
  • Save and leave (CTRL+X)
  • Restart Samba to apply changes:
    sudo service smbd restart

Test access

We now have a shared folder accessible to all without authentication.
To verify that this works, connect to the network drive:

  • Windows: Open the file explorer (Win + E) and type the following address: \\X.X.X.X\SharePi
  • Linux/Mac: Open the file explorer and type the following address: smb://X.X.X.X/SharePi

Make sure the folder opens, and that you can create files or folders, and then delete them without permissions issues.
If so, we can move on.

Permissions

For now, our share is accessible to anyone, even without a password.
If you do not want your little sister to delete your backup history, you will have to forbid guest access.

Configuration

To request a password when connecting, edit the public option in /etc/samba/smb.conf:

[SharePi] 
comment = RaspberryPi
public = no
writeable = yes
browsable = yes 
path = /media/share
create mask = 0777
directory mask = 0777

You must also tell samba that the user is allowed to connect to shares:
sudo smbpasswd -a pi

Then restart Samba:
sudo service smbd restart

If you try to connect again, it should open an authentication window.
If this is not the case, check that you are not already connected in guest mode (first you must disconnect, it depends on your OS, so restart your computer if you can’t find).
On Ubuntu, I had to click on the “Eject” button in front of the mount in the file explorer.

Add another user

If necessary, you can add other user accounts with different passwords:

  • Create a new user:
    sudo adduser yourname
  • Allow samba access for it:
    sudo smbpasswd -a yourname

You can now connect with any of the users.

But remember that we put everyone’s rights on the /media/share folder, so all users you create will have the same permissions.
If, for example, you want only the “pi” user to have access to the SharePi share, you will have to change it like this :

chown pi /media/share -R
chmod 700 /media/share -R

You can then create multiple shares by changing user permissions for each one.

By the way, depending on the number of users and the type of files you host on your Raspberry Pi, installing an antivirus on it might be something worth to consider. Linux isn’t the most exposed operating system, but it can protect Windows users.

Turn the Raspberry Pi into a media server

Now that we have a network storage location, why don’t we use it to manage our downloads and make it accessible from our TV?

Torrent server

You probably know the Torrent protocol, which is a well-known protocol for downloading.
We will see how to install a torrent server on our Raspberry Pi to automate downloads.

Create a new folder for torrents to download:
sudo mkdir /media/share/torrents
sudo chmod 777 /media/share/torrents

Rtorrent

  • Start by installing rtorrent and screen:
    sudo apt-get install rtorrent screen
  • Then create your configuration file:
    nano ~/.rtorrent.rc
  • Paste these lines:
    directory = /media/share/torrents
    You can add all the options that interest you. You will find a list here
  • Start rtorrent:
    screen -s /bin/bash rtorrent
  • Leave the screen without closing rtorrent with CTRL+A and CTRL+D
  • Go back to the screen with screen -r

Screen allows you to let run rtorrent even when you disconnect.

Web interface

We will now add the flood interface which will allow us to manage all this from a remote computer.

  • Firstly, you need to install npm:
    sudo apt-get install npm
  • Then add nod-gyp mod:
    sudo npm install -g node-gyp
  • Now, clone the git repository of the flood web interface like this:
    cd /opt
    sudo git clone https://github.com/jfurrow/flood.git
  • And run this commands to install and start it:
    cd /opt/flood
    sudo npm install --unsafe-perm
    sudo npm run build
    sudo npm start

This step will take a while, drink a coffee.

After the installation is complete and the application started, you can access the interface at http://X.X.X.X:3000.

flood interface

If you need additional information about the configuration options, you can check their GitHub page.

DLNA

DLNA is a technology that allows you to play a video stream on one device from a file stored on another.
Typically, you can play a movie stored on your Raspberry Pi from your smart TV or PS4.

The package that makes it possible on Debian is called minidlna.
So we will install and configure it to stream the contents of our shared folder:

  • Install the package:
    sudo apt-get install minidlna
  • Edit the configuration file:
    sudo nano /etc/minidlna.conf
  • Set the shared folder in the line that starts with media_dir=
    media_dir=A,/media/share
    You can set it as a subfolder like /media/share/movies if you want
  • Start the service:
    sudo service minidlna start

MiniDLNA will then scan your folder and make it available from all your compatible devices.

Improve your file server

NAS distribution

If you do not want to manage all this with complicated commands and configuration files, there is a solution that may interest you.
Indeed, there are dedicated distributions for managing a file server, which let you configure everything via a web interface.

This is the case of OpenMediaVault which is available for Raspberry Pi.
You will find the images to download on SourceForge.
Edit: That’s no longer available on Sourceforge, you can now install it on Raspberry Pi OS by following this guide. I will probably do an article about it soon.

Once installed on an SD card, you will have an interface allowing you to manage your shares, your users, etc …

openmediavault raspberry pi

RAID or backups

We talked about using this file server as a backup in this article.
You still have to avoid using it as a primary storage server.
Copying all of your photos from the last ten years without storing them elsewhere does not seem like an excellent idea.

Whether you have chosen the SD card or USB hard drive option, these are not very reliable storage methods.
A hardware failure quickly arrives, and most of the time you will lose all content.

If you want to make it a primary storage server, you should not forget about security.
It is possible to install multiple disks in a RAID (with data replication) on Raspberry Pi, either in USB or with an additional SATA card.

But the simplest is perhaps to have backups of this server elsewhere.
We can imagine a second SD card on which is copied regularly the content of the first. Or a second Raspberry Pi that will serve as a backup.

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.

Conclusion

I hope all of this will help you set up your file server at home.

To sum up, it’s simple to create a file sharing accessible to all on Raspberry Pi.
However, it is often necessary to spend a little more time adding the required options to implement what you want successfully.

In any case, you have here a good information base to create a sharing server, a torrent server or a media server.

Additional Resources

Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.

Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Download the e-book.

VIP Community
If you just want to hang out with me and other Raspberry Pi fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Create, understand, and improve any Python script for your Raspberry Pi.
Learn the essentials step-by-step without losing time understanding useless concepts.
Get the e-book now.

You can also find all my recommendations for tools and hardware on this page.

How to Turn a Raspberry Pi into a File Server

A Raspberry Pi is a small, affordable, and versatile computer that can be used for a variety of projects. One of the most popular uses for a Raspberry Pi is to turn it into a file server. With a file server, you can store and share files with multiple users over a network. Here’s how to turn your Raspberry Pi into a file server.

Step 1: Install Raspbian

The first step is to install the Raspbian operating system on your Raspberry Pi. Raspbian is a Linux-based operating system specifically designed for the Raspberry Pi. You can download the latest version of Raspbian from the Raspberry Pi website and install it on your Raspberry Pi using an SD card.

Step 2: Set Up the Network

Once you have Raspbian installed, you need to set up the network. You can either connect your Raspberry Pi to your existing network or create a new one. If you’re creating a new network, you’ll need to configure the network settings on your Raspberry Pi. You can do this by using the raspi-config command in the terminal.

Step 3: Install Samba

Samba is a software package that allows you to share files over a network. To install Samba on your Raspberry Pi, open the terminal and type in the following command:

sudo apt-get install samba samba-common-bin

Step 4: Configure Samba

Once Samba is installed, you need to configure it. To do this, open the Samba configuration file in a text editor. You can find the configuration file at /etc/samba/smb.conf. In the configuration file, you can set up the shares that you want to make available to other users. You can also set up user accounts and passwords for each user.

Step 5: Start the Samba Service

Once you’ve configured Samba, you need to start the Samba service. To do this, open the terminal and type in the following command:

sudo service smbd start

Step 6: Access the File Server

Once the Samba service is running, you can access the file server from other computers on the network. To do this, open the file explorer on the other computer and type in the IP address of the Raspberry Pi. You should then be able to access the shared files on the Raspberry Pi.

Conclusion

Turning your Raspberry Pi into a file server is a great way to store and share files with multiple users over a network. With a few simple steps, you can set up a file server on your Raspberry Pi and start sharing files with other users.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?