Complete Home Server Guide Part 4: File Server Setup
Samba, NFS, SFTP Configuration and RAID Basics
Introduction: Why a File Server?
One of the biggest reasons for building a home server is the file server. Cloud services are convenient, but you have to pay monthly subscription fees and there are storage capacity limits. More importantly, you might feel uneasy about having your precious data stored on another company's servers.
Building your own file server frees you from these concerns. Once you buy the hard drives, you can use unlimited storage without additional costs, and your data exists only inside your home. Let us create our own cloud where we can safely store family photos, videos, documents and access them from anywhere.
In this part, we will focus on Samba and NFS, the core technologies of file servers, and cover how to access files from various devices and reliable disk management methods.
1. File Sharing Protocol Comparison
1.1 Overview of Major Protocols
There are several ways to share files over a network. Understanding each characteristic and choosing appropriately for your situation is important.
| Protocol | Primary Use | Pros | Cons |
|---|---|---|---|
| Samba (SMB/CIFS) | Windows compatibility | Supports all OSes, easy setup | Relatively slow |
| NFS | Linux/Unix environments | Fast speed, low overhead | Limited Windows support |
| SFTP | Secure file transfer | Encrypted, firewall-friendly | Inconvenient for real-time access |
| WebDAV | Web-based access | Accessible from anywhere | Performance limitations |
1.2 Which Should You Choose?
For a typical home environment, I recommend the following:
- If Windows PCs are your main devices: Samba is the best choice. It connects directly as a network drive in File Explorer.
- If you only use Linux or Mac: NFS is faster and more efficient.
- If you have a mixed environment: Set up both Samba and NFS. You can share the same folder through both protocols.
- If you need external access: It is safest to access through VPN to your internal network, or use SFTP.
2. Building a Samba File Server
2.1 Installing Samba
Samba is an implementation of Windows' file sharing protocol (SMB) on Linux. It is the most universally used as you can access it directly from Windows File Explorer.
# Install Samba
sudo apt update
sudo apt install samba samba-common-bin
# Check service status
sudo systemctl status smbd
# Check version
smbd --version
2.2 Creating Shared Directories
Create directories for file sharing and set appropriate permissions.
# Create shared directories
sudo mkdir -p /srv/samba/public
sudo mkdir -p /srv/samba/private
# Set permissions for public folder (accessible to all users)
sudo chmod 777 /srv/samba/public
# Set permissions for private folder
sudo chmod 770 /srv/samba/private
sudo chown -R root:sambashare /srv/samba/private
2.3 Creating Samba Users
Samba manages its own user database separately from system accounts. Only users with system accounts can be registered as Samba accounts.
# Create system user if one doesn't exist
sudo useradd -M -s /usr/sbin/nologin sambauser
# Register Samba user and set password
sudo smbpasswd -a sambauser
# Enable user
sudo smbpasswd -e sambauser
# Add user to sambashare group
sudo usermod -aG sambashare sambauser
2.4 Samba Configuration
Edit the Samba configuration file to define shared folders.
# Backup existing configuration
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
# Edit configuration file
sudo nano /etc/samba/smb.conf
Add the following content to the end of the configuration file:
# Public share folder (guest access allowed)
[Public]
comment = Public Shared Folder
path = /srv/samba/public
browseable = yes
read only = no
guest ok = yes
create mask = 0666
directory mask = 0777
# Private share folder (authentication required)
[Private]
comment = Private Shared Folder
path = /srv/samba/private
browseable = yes
read only = no
guest ok = no
valid users = @sambashare
create mask = 0660
directory mask = 0770
# User home directories
[homes]
comment = Home Directories
browseable = no
read only = no
create mask = 0700
directory mask = 0700
valid users = %S
Verify the configuration and restart the service:
# Check configuration syntax
testparm
# Restart Samba services
sudo systemctl restart smbd nmbd
# Enable auto-start on boot
sudo systemctl enable smbd nmbd
2.5 Firewall Configuration
# Allow Samba ports
sudo ufw allow samba
# Or allow individual ports
sudo ufw allow 139/tcp
sudo ufw allow 445/tcp
sudo ufw allow 137/udp
sudo ufw allow 138/udp
3. Connecting to Samba from Clients
3.1 Connecting from Windows
Method 1: Direct Access in File Explorer
- Open File Explorer and type
\\192.168.1.100in the address bar (server IP) - Shared folders list will appear
- Enter username and password when accessing Private folder
Method 2: Map Network Drive
- Right-click "This PC" in File Explorer
- Select "Map network drive"
- Choose a drive letter (e.g., Z:)
- Enter
\\192.168.1.100\Privatein Folder field - Check "Connect using different credentials"
- Check "Reconnect at sign-in" for auto-mount
3.2 Connecting from macOS
- In Finder menu, go to "Go" > "Connect to Server" (Cmd+K)
- Enter
smb://192.168.1.100in Server Address - Select volume to connect
- Enter username and password
Auto-mount setup:
- System Preferences > Users & Groups
- Select current user > Login Items
- Add connected network drive to the list
3.3 Connecting from Linux
Temporary mount:
# Install CIFS utilities
sudo apt install cifs-utils
# Create mount point
sudo mkdir -p /mnt/samba
# Mount (specify user)
sudo mount -t cifs //192.168.1.100/Private /mnt/samba -o username=sambauser,password=yourpassword
# Or with password prompt
sudo mount -t cifs //192.168.1.100/Private /mnt/samba -o username=sambauser
Auto-mount (fstab):
# Create credentials file (for security)
sudo nano /etc/samba/credentials
# Contents
username=sambauser
password=yourpassword
# Set permissions
sudo chmod 600 /etc/samba/credentials
# Edit fstab
sudo nano /etc/fstab
# Add the following line
//192.168.1.100/Private /mnt/samba cifs credentials=/etc/samba/credentials,iocharset=utf8,uid=1000,gid=1000 0 0
# Test mount
sudo mount -a
4. Building an NFS File Server
4.1 What is NFS?
NFS (Network File System) is the standard network file system used in Unix/Linux environments. It has less overhead than Samba and is optimized for file sharing between Linux systems.
4.2 NFS Server Installation and Configuration
# Install NFS server
sudo apt update
sudo apt install nfs-kernel-server
# Create shared directory
sudo mkdir -p /srv/nfs/shared
sudo chown nobody:nogroup /srv/nfs/shared
sudo chmod 755 /srv/nfs/shared
NFS exports configuration:
# Edit exports file
sudo nano /etc/exports
Add the following content:
# Format: shared_path allowed_IP(options)
# Allow specific subnet
/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)
# Allow specific client only
/srv/nfs/shared 192.168.1.50(rw,sync,no_subtree_check,no_root_squash)
# Read-only share
/srv/nfs/readonly 192.168.1.0/24(ro,sync,no_subtree_check)
Key options explained:
rw: Allow read/writero: Read-onlysync: Write changes immediately to diskno_subtree_check: Disable subdirectory checking (improves performance)no_root_squash: Map client root to server root
# Apply exports
sudo exportfs -a
# View current exports
sudo exportfs -v
# Restart NFS service
sudo systemctl restart nfs-kernel-server
# Enable auto-start on boot
sudo systemctl enable nfs-kernel-server
4.3 Firewall Configuration
# Allow NFS ports
sudo ufw allow from 192.168.1.0/24 to any port nfs
# Or allow specific ports
sudo ufw allow 2049/tcp
sudo ufw allow 2049/udp
4.4 NFS Client Configuration
# Install NFS client
sudo apt install nfs-common
# Create mount point
sudo mkdir -p /mnt/nfs
# Temporary mount
sudo mount 192.168.1.100:/srv/nfs/shared /mnt/nfs
# Verify mount
df -h | grep nfs
Auto-mount (fstab):
# Edit fstab
sudo nano /etc/fstab
# Add the following line
192.168.1.100:/srv/nfs/shared /mnt/nfs nfs defaults,_netdev 0 0
# Test mount
sudo mount -a
5. Managing User Access Permissions
5.1 Samba Group-Based Permissions
When you have multiple users, managing permissions through groups is convenient.
# Create groups
sudo groupadd family
sudo groupadd work
# Add users to groups
sudo usermod -aG family user1
sudo usermod -aG family user2
sudo usermod -aG work user3
# Set directory group ownership
sudo chown -R root:family /srv/samba/family
sudo chown -R root:work /srv/samba/work
# Set group write permissions
sudo chmod -R 2770 /srv/samba/family
sudo chmod -R 2770 /srv/samba/work
Add group-specific share configuration to smb.conf:
[Family]
comment = Family Shared Folder
path = /srv/samba/family
browseable = yes
read only = no
valid users = @family
create mask = 0660
directory mask = 0770
force group = family
[Work]
comment = Work Shared Folder
path = /srv/samba/work
browseable = yes
read only = no
valid users = @work
create mask = 0660
directory mask = 0770
force group = work
5.2 Individual User Permission Settings
# Only specific user can write
[Reports]
comment = Reports - Admin Write Only
path = /srv/samba/reports
browseable = yes
read only = yes
write list = admin
valid users = admin, user1, user2
6. Disk Management and RAID Basics
6.1 Checking Disk Status
# List connected disks
lsblk
# Detailed disk information
sudo fdisk -l
# Disk usage
df -h
# Check SMART status (disk health)
sudo apt install smartmontools
sudo smartctl -a /dev/sda
6.2 Formatting and Mounting New Disks
# Create disk partition
sudo fdisk /dev/sdb
# n: new partition
# p: primary partition
# Enter: use defaults
# w: save
# Create ext4 filesystem
sudo mkfs.ext4 /dev/sdb1
# Create mount point
sudo mkdir -p /mnt/data
# Mount
sudo mount /dev/sdb1 /mnt/data
# Get UUID (for fstab)
sudo blkid /dev/sdb1
# Add to fstab for auto-mount
sudo nano /etc/fstab
# UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/data ext4 defaults 0 2
6.3 RAID Basic Concepts
RAID (Redundant Array of Independent Disks) is a technology that combines multiple disks into one to improve performance or reliability.
| RAID Level | Minimum Disks | Characteristics | Capacity Efficiency |
|---|---|---|---|
| RAID 0 | 2 | Speed boost, no redundancy | 100% |
| RAID 1 | 2 | Mirroring, complete copy | 50% |
| RAID 5 | 3 | Distributed parity, 1 drive failure tolerance | (n-1)/n |
| RAID 6 | 4 | Dual parity, 2 drive failure tolerance | (n-2)/n |
| RAID 10 | 4 | Mirror + stripe combination | 50% |
6.4 Software RAID Configuration (mdadm)
As an example, let us configure RAID 1 (mirroring):
# Install mdadm
sudo apt install mdadm
# Create RAID 1 array (using sdb and sdc)
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
# Check array status
cat /proc/mdstat
sudo mdadm --detail /dev/md0
# Create filesystem
sudo mkfs.ext4 /dev/md0
# Mount
sudo mkdir -p /mnt/raid
sudo mount /dev/md0 /mnt/raid
# Save mdadm configuration
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u
# Add to fstab
echo '/dev/md0 /mnt/raid ext4 defaults 0 2' | sudo tee -a /etc/fstab
Important: RAID does not replace backups. RAID is only protection against hardware failure; it is useless if you accidentally delete files or get infected with ransomware. Always maintain separate backups.
7. Secure File Transfer with SFTP
7.1 SFTP Configuration
SFTP is a secure file transfer protocol based on SSH. If SSH is installed, you can use it immediately without separate installation.
# Create SFTP-only user
sudo useradd -m -s /usr/sbin/nologin sftpuser
sudo passwd sftpuser
# Set up SFTP-only directory
sudo mkdir -p /home/sftpuser/files
sudo chown root:root /home/sftpuser
sudo chmod 755 /home/sftpuser
sudo chown sftpuser:sftpuser /home/sftpuser/files
SFTP chroot configuration in SSH settings:
sudo nano /etc/ssh/sshd_config
Add at the end of file:
Match User sftpuser
ChrootDirectory /home/sftpuser
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
# Restart SSH
sudo systemctl restart ssh
7.2 SFTP Client Connection
Command line:
# Connect via SFTP
sftp sftpuser@192.168.1.100
# Basic commands
ls # Remote directory listing
lls # Local directory listing
cd files # Change directory
put file.txt # Upload
get file.txt # Download
bye # Exit
Recommended GUI clients:
- Windows: WinSCP, FileZilla
- macOS: Cyberduck, FileZilla
- Linux: FileZilla, Nautilus (built-in)
8. Summary and Next Steps
In this part, we covered how to turn your home server into a full-fledged file server. We set up Samba for Windows-compatible file sharing, connected Linux clients quickly with NFS, and secured data reliability with RAID.
File Server Setup Checklist
- Is Samba installed and working properly?
- Can you connect as a network drive from Windows/Mac?
- Are user access permissions set correctly?
- Is NFS mounting from Linux clients?
- Are necessary ports allowed in the firewall?
- Is disk status normal? (Check SMART)
- Do you have a backup plan for important data?
Performance Optimization Tips
- Gigabit Ethernet: Build at least a 1Gbps network environment. 90% of file server performance depends on the network.
- SSD Cache: Place frequently accessed files on SSD, bulk storage on HDD.
- Jumbo Frames: If your network equipment supports it, setting MTU to 9000 improves efficiency for large transfers.
In the next part, we will cover setting up various services using Docker. We will cover practical services like creating your own cloud storage with Nextcloud, and building a media server with Plex or Jellyfin.