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:
- Download and install Raspberry Pi Imager from the official website
- Flash Raspberry Pi OS to your microSD card
- Before ejecting the SD card, enable SSH by creating an empty file named
ssh
in the boot partition - If using Wi-Fi, create a file named
wpa_supplicant.conf
in the boot partition with your network credentials - Insert SD card into Pi and power on
- Locate the Pi's IP address using your router's admin interface
6. Initial SSH connection and configuration:
- Connect to Pi via SSH:
ssh pi@[PI_IP_ADDRESS]
- Default password is
raspberry
- 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:
8. External storage preparation:
- Connect external USB drive to a USB 3.0 port (blue connector)
- Identify the drive:
sudo fdisk -l
- Create mount point:
sudo mkdir /mnt/fileserver
- Format drive if needed:
sudo mkfs.ext4 /dev/sda1
- Mount the drive:
sudo mount /dev/sda1 /mnt/fileserver
- Set proper ownership:
sudo chown -R pi:pi /mnt/fileserver
9. Permanent drive mounting:
- Get drive UUID:
sudo blkid
- Edit fstab:
sudo nano /etc/fstab
- Add line:
UUID=[your-drive-uuid] /mnt/fileserver ext4 defaults,auto,users,rw,nofail 0 0
- Test automatic mounting:
sudo umount /mnt/fileserver && sudo mount -a
10. Samba installation:
Install Samba server and common utilities:
11. Samba configuration:
- Backup original configuration:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
- Edit Samba configuration:
sudo nano /etc/samba/smb.conf
- Add the following share configuration at the end of the file:
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:
Enter password when prompted (can be different from system password)
13. Samba service management:
Enable and start Samba services:
sudo systemctl enable smbd
sudo systemctl restart nmbd
sudo systemctl enable nmbd
14. SSH security configuration:
- Edit SSH daemon configuration:
sudo nano /etc/ssh/sshd_config
- Modify the following settings:
Port 2222
(change from default port 22)PermitRootLogin no
PasswordAuthentication yes
AllowUsers pi
- Restart SSH service:
sudo systemctl restart ssh
15. Firewall installation and configuration:
- Install UFW firewall:
sudo apt install ufw -y
- Set default policies:
sudo ufw default allow outgoing
3. Allow necessary services:
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 usermod -aG sambashare [username]
sudo smbpasswd -a [username]
17. Directory structure setup:
Create organized directory structure:
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:
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:
21. Status verification:
Check service status:
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.