Raspberry Pi File Server Setup

Step-by-step instructions for setting up a file server with Samba, SSH, and firewall security.

These procedures apply to Raspberry Pi 5, 4 or 3 with Raspberry Pi OS (64-Bit), (32-Bit) or (Legacy, 32-Bit) with or without Samba, SSH, and/or firewall configurations.

1. General:

The procedures below are optimized for setting up a file server on a Raspberry Pi 5, 4 or 3 with Raspberry Pi OS (64-Bit), (32-Bit) or (Legacy, 32-Bit) connected via Ethernet. Management connectivity is provided via SSH. A firewall is included for security.

2. Internet access during setup:

Many of the steps below assume and require the target Raspberry Pi to have Internet access during setup. This is typically accomplished by connecting the Pi to a router via Ethernet cable or Wi-Fi.

3. Hardware requirements:

  • Raspberry Pi 5, 4, or 3
  • MicroSD card (32GB or larger, Class 10 recommended)
  • External USB drive or SSD for file storage
  • Ethernet cable (recommended) or Wi-Fi connection
  • Power supply appropriate for your Pi model

4. Software requirements:

  • Raspberry Pi OS (Latest version recommended)
  • SSH client software (PuTTY for Windows, Terminal for Mac/Linux)

5. Initial OS Installation:

  1. Download and install Raspberry Pi Imager from the official website
  2. Flash Raspberry Pi OS to your microSD card
  3. Before ejecting the SD card, enable SSH by creating an empty file named ssh in the boot partition
  4. If using Wi-Fi, create a file named wpa_supplicant.conf in the boot partition with your network credentials
  5. Insert SD card into Pi and power on
  6. Locate the Pi's IP address using your router's admin interface

6. Initial SSH connection and configuration:

  1. Connect to Pi via SSH: ssh pi@[PI_IP_ADDRESS]
  2. Default password is raspberry
  3. Run sudo raspi-config to configure:
    • Change default password
    • Enable SSH (if not already enabled)
    • Expand filesystem to use full SD card
    • Set timezone and locale
    • Reboot when configuration is complete

7. System updates:

Update the system packages to ensure security and compatibility:

sudo apt update && sudo apt upgrade -y

8. External storage preparation:

  1. Connect external USB drive to a USB 3.0 port (blue connector)
  2. Identify the drive: sudo fdisk -l
  3. Create mount point: sudo mkdir /mnt/fileserver
  4. Format drive if needed: sudo mkfs.ext4 /dev/sda1
  5. Mount the drive: sudo mount /dev/sda1 /mnt/fileserver
  6. Set proper ownership: sudo chown -R pi:pi /mnt/fileserver

9. Permanent drive mounting:

  1. Get drive UUID: sudo blkid
  2. Edit fstab: sudo nano /etc/fstab
  3. Add line: UUID=[your-drive-uuid] /mnt/fileserver ext4 defaults,auto,users,rw,nofail 0 0
  4. Test automatic mounting: sudo umount /mnt/fileserver && sudo mount -a

10. Samba installation:

Install Samba server and common utilities:

sudo apt install samba samba-common-bin -y

11. Samba configuration:

  1. Backup original configuration: sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
  2. Edit Samba configuration: sudo nano /etc/samba/smb.conf
  3. Add the following share configuration at the end of the file:
[FileServer]
comment = Network File Server
path = /mnt/fileserver
browseable = yes
writeable = yes
only guest = no
create mask = 0777
directory mask = 0777
public = no
valid users = pi

12. Samba user setup:

Create Samba user account:

sudo smbpasswd -a pi

Enter password when prompted (can be different from system password)

13. Samba service management:

Enable and start Samba services:

sudo systemctl restart smbd
sudo systemctl enable smbd
sudo systemctl restart nmbd
sudo systemctl enable nmbd

14. SSH security configuration:

  1. Edit SSH daemon configuration: sudo nano /etc/ssh/sshd_config
  2. Modify the following settings:
    • Port 2222 (change from default port 22)
    • PermitRootLogin no
    • PasswordAuthentication yes
    • AllowUsers pi
  3. Restart SSH service: sudo systemctl restart ssh

15. Firewall installation and configuration:

  1. Install UFW firewall: sudo apt install ufw -y
  2. Set default policies:
sudo ufw default deny incoming
sudo ufw default allow outgoing

3. Allow necessary services:

sudo ufw allow 2222/tcp comment 'SSH'
sudo ufw allow 445/tcp comment 'Samba SMB'
sudo ufw allow 139/tcp comment 'Samba NetBIOS'
sudo ufw allow from 192.168.1.0/24 comment 'Local Network'

4. Enable firewall: sudo ufw --force enable

16. User management (optional):

To create additional users for the file server:

sudo adduser [username]
sudo usermod -aG sambashare [username]
sudo smbpasswd -a [username]

17. Directory structure setup:

Create organized directory structure:

sudo mkdir /mnt/fileserver/shared
sudo mkdir /mnt/fileserver/private
sudo chmod 777 /mnt/fileserver/shared
sudo chown pi:pi /mnt/fileserver/private

18. Performance optimization:

Add performance settings to /etc/samba/smb.conf under [global] section:

socket options = TCP_NODELAY IPTOS_LOWDELAY
read raw = yes
write raw = yes
max xmit = 65536

19. Testing file server access:

  • Windows: Open File Explorer, type \\[PI_IP_ADDRESS]\FileServer
  • Mac: Open Finder, press Cmd+K, type smb://[PI_IP_ADDRESS]/FileServer
  • Linux: Open file manager, type smb://[PI_IP_ADDRESS]/FileServer

20. Testing SSH access:

Connect using new SSH port:

ssh -p 2222 pi@[PI_IP_ADDRESS]

21. Status verification:

Check service status:

sudo systemctl status smbd
sudo systemctl status ssh
sudo ufw status verbose

22. Troubleshooting:

  • Cannot access shares: Verify firewall rules and Samba user passwords
  • Slow performance: Check USB 3.0 connection and network speed
  • Permission denied: Verify file permissions and user group membership
  • SSH connection refused: Check port number and firewall configuration

23. Log file locations:

  • Samba logs: /var/log/samba/
  • SSH logs: /var/log/auth.log
  • System logs: /var/log/syslog
  • Firewall logs: /var/log/ufw.log

24. Maintenance procedures:

Regular maintenance tasks:

  • Monitor disk usage: df -h
  • Check system resources: htop
  • Review logs for errors
  • Update system packages monthly
  • Test backup and restore procedures

Summary

Setup time: Approximately 30-45 minutes

Hardware cost: Under $100 for complete system

Performance: Suitable for home and small office file sharing requirements

Need Help?

Having trouble with your Raspberry Pi setup? Contact our technical support team serving Leesburg, FL and Central Florida.

352-360-5553 | info@systemsolvesolutions.com