0% found this document useful (0 votes)
27 views9 pages

Build a Raspberry Pi File Server

This document provides instructions for setting up a personal cross-platform file server on a Raspberry Pi using Samba. It discusses installing Samba and additional packages, configuring shares and permissions for external drives, and accessing the file server from other devices on the home network.

Uploaded by

efsc70
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views9 pages

Build a Raspberry Pi File Server

This document provides instructions for setting up a personal cross-platform file server on a Raspberry Pi using Samba. It discusses installing Samba and additional packages, configuring shares and permissions for external drives, and accessing the file server from other devices on the home network.

Uploaded by

efsc70
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

|

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 in the market that 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 would be 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.

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.

As the front page at [Link] says: Samba is a software package that gives network administrators
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 a few configurations, you can
build a personal cross-platform file-sharing server on Raspberry Pi at your home, which provides a
central storage and is capable of sharing files with other computers, smart TV, smartphone, and
other smart devices.

• A Raspberry Pi device
• MicroSD card loaded with Raspberry Pi OS
• External storage drives (hard drives, SSDs, flash drives, etc.) that are formatted and partitioned
• Ethernet cable or WiFi connectivity

• Latest version of Raspberry Pi OS installed


• Samba installed for implementing SMB/CIFS file sharing protocols
• ExFAT and NTFS support packages (exfat-utils, exfat-fuse, ntfs-3g)
• Text editor like nano or vim for editing configuration files

• Basic understanding of Linux file systems and permissions


• Familiarity with Samba configuration and how to define shares
• Know how to connect external drives to Raspberry Pi
• Understanding of SMB/CIFS protocols for cross-platform file sharing
• Ability to use the command line for software installation, editing files, etc.

• The Raspberry Pi needs to be connected to the local home network via Ethernet or WiFi
• Unique hostname defined for accessing shared folders
• Configure router to allow access to Samba shares from other devices on network

Start by ensuring all hardware components are set up properly, Raspberry Pi OS is updated fully,
Samba packages are installed, and you have partitions formatted on the external drives. Also make
sure you have adequate Linux admin knowledge before editing configs.

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.

Type ‘y’ and let the installation continue.


Install samba on Raspberry Pi

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.

Setting up DHCP client on Raspberry Pi

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 the EXT4 file system. And we have mounted both partitions under the/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 partition the drive “How to Partition and Format the Hard
Drives on Raspberry Pi?”. We recommend reading that post before you proceed.

This image is captured by the author

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, . All three permission are
applied to three types of user entities, .

1. � 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. � In Linux, all files and directories will also have a group, a collection of users belong to the
group.
3. � Finally, everyone else.

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

1. ‘d’ represents it’s a directory. In case of any other files you may see ‘-‘.
2. � Represents the Read ‘r’, Write ‘w’, and Execute ‘x’ permissions for the ‘User’.
3. Represents the Read ‘r’, Write ‘w’, and Execute ‘x’ permissions for the ‘Group’.
4. Represents the Read ‘r’, Write ‘w’, and Execute ‘x’ permissions for the ‘Others’.

In the above picture, 1st char of both files are ‘d’, and 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 types of users have all permission on it. This shows that the
Linux system manages the permissions differently on the different types of file systems. 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 assigning permissions to them rather than managing
the permissions at the level of the partition.

Creating a public directory for ext4 and NTFS filesystems

List the files under the data-ext4 directory

You can manipulate the permission by using ‘ ‘ command. To grant the missing write
permissions on the ext4 public directory, type the following command.
Here ‘go’ stands for Group and Other users, ‘+’ represents adding permissions, ‘w’ stands for Write
permission. Please refer to the chmod and commands for more information https://
[Link]/unix/[Link]

Assigning the write permission to the ext4 public directory

Let’s back to our original topic. Share the public directories created on both partitions by configuring
[Link] file. Open the file using your choice of text editor. We are using nano text editor for
demonstration purposes.

The workgroup setting is important when you want to access 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 it as default.
1. [public-ntfs]path = /mnt/data-ntfs/publicpublic = yeswriteable = yes
That’s it. Your Samba service should pick up the changes on its own, and sharing should be running
already. Try rebooting the service if it didn’t.

1. � $ sudo apt update && apt upgrade


2. $ sudo apt install
exfat-utils exfat-fuse ntfs-3g
3. . To add a user account,
open the file /etc/samba/[Link] in any text editor and add the ‘valid user = user1’ line.
4. If you can’t connect your Pi with its name, try this. ‘ 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.
• How to Fix the 4 High-Severity Vulnerabilities in Samba?
• Step-by-Step Procedure to Set Up An Active Directory On Ubuntu
• How To Fix The Out-Of-Bounds Write Vulnerability In Samba vfs_fruit Module �CVE�2021�44142�

Arun KL is a cybersecurity professional with 15� years of experience in IT


infrastructure, cloud security, vulnerability management, Penetration Testing,
security operations, and incident response. He is adept at designing and
implementing robust security solutions to safeguard systems and data. Arun
holds multiple industry certifications including CCNA, CCNA Security, RHCE,
CEH, and AWS Security.

Login

Add a comment

M ↓ MARKDOWN ADD COMMENT

Powered by Commento

Common questions

Powered by AI

To set up external storage for file sharing on a Raspberry Pi, first, format and partition the external drives using a compatible file system like ext4. Connect these drives to the Raspberry Pi, mount them at a standard mount point (e.g., /mnt/data-ext4). Ensure the Raspberry Pi is equipped with necessary packages like exfat-utils or ntfs-3g for non-native file systems. Configure Samba to share these mount points and specify access permissions in the smb.conf file. Finally, secure the shares with proper Linux file permissions and verify network visibility .

For managing file permissions on a Linux-based file server, use the Linux file permission model which involves setting read, write, and execute permissions for the user, group, and others. Use the 'chmod' command to assign the correct permissions to files and directories as needed. For network shares, define permissions in the Samba configuration file and utilize Samba's user-level permissions. Avoid NTFS for directories requiring strict access control as Linux can't enforce its native permission rules on it .

Samba implements Server Message Block/Common Internet File System (SMB/CIFS) protocols, which are supported by multiple operating systems including Windows, Linux, and Mac. This protocol allows for the sharing of files over a network, making it possible to set up a cross-platform file-sharing server on a Raspberry Pi. Through Samba, the Raspberry Pi can be configured to share storage across the network with various devices such as computers, smart TVs, and smartphones .

When using NTFS for a personal file server on Linux, a significant security consideration is the lack of granular permission control. Unlike ext4, which uses Linux's native file permission system, NTFS does not integrate these controls effectively in a Linux environment. This can lead to all users having full permissions (read, write, execute) by default, which could be a security risk. Thus, it's recommended to use public directories with managed permissions rather than relying on NTFS's default settings .

To ensure proper network access for Samba shares on a Raspberry Pi, start by setting a unique hostname for the Raspberry Pi to enable devices to easily access shared resources. Update the Samba configuration file with correct workgroup settings to match your network's settings. Configure your router to allow access to the Samba shares. Test connectivity by accessing the shares from different network devices. Ensure correct user permissions and follow necessary network security protocols to protect shared data .

On Linux, file permissions are traditionally managed through user, group, and others categories with permissions settings such as read ('r'), write ('w'), and execute ('x'). The ext4 file system adheres strictly to these permissions, allowing granular control. However, NTFS on Linux does not honor these permissions in the same way since NTFS is a Windows file system and Linux can't enforce its native permission controls on it. As a result, NTFS often allows broader permissions such as read, write, and execute for all user types when mounted in a Linux environment .

Samba is popular for implementing file sharing over a network on a Raspberry Pi due to its flexibility, compatibility, and support for SMB/CIFS protocols, which are recognized by most major operating systems including Windows, Linux, and Mac. This widespread compatibility makes it easier to connect multiple types of devices for file sharing across a network. Additionally, Samba can be configured to fit a wide variety of network setups, making it a versatile choice .

While setting up file shares on a Raspberry Pi, the choice of file system impacts the permissions you can enforce. ext4 is a native Linux file system and supports traditional Linux permission settings (read, write, execute) for user, group, and others. On the other hand, NTFS, which is primarily used by Windows, doesn't support these controls as granularly when utilized in Linux environments. This can lead to broader permissions being defaulted for NTFS, impacting security and access controls when setting up shares .

To set up a Raspberry Pi as a file server using Samba, you need the following components: a Raspberry Pi device with Raspberry Pi OS installed on a MicroSD card, external storage drives formatted and partitioned, Ethernet or WiFi connectivity, and Samba installed to implement SMB/CIFS protocols. Additionally, knowledge of Linux file systems, permissions, and Samba configurations is essential. A text editor like nano or vim is needed for editing configuration files .

To configure Samba for sharing a public directory on both ext4 and NTFS file systems, open the smb.conf file in a text editor like nano. Define the share in the configuration file with paths for both file systems. For example, use the path for the ext4-mounted directory and another for the NTFS-mounted directory. Set the directories as public and writable. Restart the Samba service to apply the changes. Adjust workgroup settings if accessing from Windows, and ensure valid user permissions are set .

You might also like