Skip to content

Instantly share code, notes, and snippets.

@KageKirin
Last active December 18, 2022 16:00
Show Gist options
  • Save KageKirin/ccce50f70f5d04424df5fe40a137e43a to your computer and use it in GitHub Desktop.
Save KageKirin/ccce50f70f5d04424df5fe40a137e43a to your computer and use it in GitHub Desktop.
Sharing a folder from a Raspberry Pi over multiple network protocols

Sharing a folder from a Raspberry Pi over multiple network protocols

Let's presume we have a specific folder on a Raspi that we want to share over the network, be it for file read/write access as a drive or as a media streaming endpoint.

The following sections explain how to configure the different protocol daemons.

For the sake of consistency, we define our shared folder as /mnt/mountpoint/share and a user account without root priviledges pi.

## create user
sudo adduser pi

## add user to group 'users'
sudo usermod -a -G users pi 

## create group 'shareusers'
sudo groupadd shareusers

## add 'pi' to 'shareusers'
sudo usermod -a -G shareusers pi 

Samba

Installation

sudo apt install samba samba-common-bin avahi-daemon

Setup

sudo nano /etc/samba/smb.conf
# /etc/samba/smb.conf

[Share]
Comment = Raspberry Pi Shared Folder
Path = /mnt/mountpoint/share
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes

Optionally, add a [global] section to the top to specify protoctol versions.

# /etc/samba/smb.conf

[global]
client min protocol = SMB3
client max protocol = SMB3
lanman auth = yes
keepalive = 0

Provide a (optionally different) password for user pi.

sudo smbpasswd -a pi

Start

sudo systemctl start smbd

Access

# Windows
\\my-raspi\Share

# Posix
smb://my-raspi/Share

NFS

Installation

sudo apt install nfs-kernel-server

Setup

sudo nano /etc/exports
# /etc/exports

/mnt/mountpoint/share *(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)

Start

sudo exportfs -ra

Access

nfs://my-raspi/mnt/mydrive/share

Apple Talk

Installation

sudo apt install netatalk avahi-daemon

OR

Install more recent version from source

Set up Netatalk

sudo nano /etc/nsswitch.conf
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat
gshadow:        files

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4 mdns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

Set up Avahi (Bonjour)

sudo nano /etc/netatalk/afp.conf
# /etc/netatalk/afp.conf

[Share]
  path = /mnt/mountpoint/share

Start Avahi

sudo service avahi-daemon start

Start Netatalk

sudo service netatalk start

Access

afp://my-raspi/Share

Rsync

The Rsync daemon can expose any folder to read/write access over rsync. rsync can be used without running the daemon, via SSH or SMB. This guide descibes how to install the daemon.

Installation

sudo apt install rsync xinetd

Set up /etc/default/rsync

sudo nano /etc/default/rsync
# /etc/default/rsync

RSYNC_ENABLE=inetd
RSYNC_CONFIG_FILE=/etc/rsyncd.conf

RSYNC_NICE='10'
RSYNC_IONICE='-c3'

Set up /etc/rsyncd.conf

sudo nano /etc/rsyncd.conf
# /etc/rsyncd.conf

max connections = 2
log file = /var/log/rsync.log
timeout = 300

[Share]
comment = Rsync Share
path = /mnt/mountpoint/share
read only = no
list = yes
uid = pi
gid = shareusers
auth users = pi
secrets file = /etc/rsyncd.secrets

Set up /etc/rsyncd.secrets

sudo nano /etc/rsyncd.secrets
sudo chmod 600 /etc/rsyncd.secrets
# /etc/rsyncd.secrets

pi:password

Set up xinetd /etc/xinetd.d/rsync

sudo nano /etc/xinetd.d/rsync
# /etc/xinetd.d/rsync

service rsync
{
    disable = no
    socket_type = stream
    wait = no
    user = root
    server = /usr/bin/rsync
    server_args = --daemon
    log_on_failure += USERID
    flags = IPv6
}

Start rsyncd through xinetd

sudo service xinetd restart 

(S)FTP

sudo apt install python3
python3 -m pip install python-ftp-server

python3 -m python-ftp-server -d "/mnt/mountpoint/share"

DO NOT USE FILEZILLA!


HTTP

The simplest way to get a cheap HTTP server, is to run Python's http.simple on a specified share. It's not utterly performant, nor secure, but it's good enough to get access to a few files over HTTP.

(And since we're aiming for a local LAN access, it's ok. -- YMMV for production usage).

sudo apt install python3
python3 -m pip install http.simple

python3 -m http.simple 8100 ## e.g. for port 8100

WebDAV


UPNP / DLNA

sudo apt install minidlna

don't install Plex as it forces you to login to their service to access your own data


Rclone

Rclone allows to mount a number a networked/cloud file services and to expose them through another network service. E.g. Google Drive to FTP or Local drive to DLNA is possible as well.

sudo apt install rclone

TODO: test configs


Sources

HTGWA: Create a Samba (SMB) share on a Raspberry Pi
HTGWA: Create an NFS share in Linux on a Raspberry Pi
Assign Read/Write Access to a User on Specific Directory in Linux
Raspberry Pi Time Machine (2021 update)
Python3 SimpleHTTPServer: The Complete Guide
Raspberry Pi Documentation
How to setup the rsync daemon on Linux
(in German) Tutorial: Raspberry Pi als rsync-Server für Backup der DS basteln
(in German) rsync on ubuntuusers.de

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment