Skip to content
Build a Home NAS with Ubuntu Server and Samba: Complete Guide
Operations 12 min read

Build a Home NAS with Ubuntu Server and Samba: Complete Guide

This tutorial shows how to repurpose an old computer into a network-attached storage (NAS) server using Ubuntu Server 24.04 LTS and Samba, covering hardware preparation, disk mounting, user setup, SMB configuration, firewall rules, cross-platform access, and troubleshooting tips for reliable local file sharing.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast

Why an Old PC Can Serve as a NAS

NAS (Network Attached Storage) centralizes files on a device that stays online, letting computers on the same network read and write via shared protocols. For home use, an old PC or mini PC with ~4 GB RAM, a healthy disk, and a wired Ethernet connection is sufficient for documents, photos, and videos. Use an SSD for the OS and reserve large-capacity disks for data. The only extra hardware cost is additional data/backup disks; Samba is free and works across Windows, macOS, and Linux via SMB.

Windows, macOS, and Linux connecting to a Linux NAS through a home router using SMB port 445.
Windows, macOS, and Linux connecting to a Linux NAS through a home router using SMB port 445.

Home LAN NAS topology.

Prepare the System, Disk, and Static IP

Assuming Ubuntu Server 24.04 LTS is installed. First inspect network interfaces and disks:

ip -br -4 addr
ip -br link
lsblk -o NAME,SIZE,FSTYPE,UUID,MOUNTPOINTS

If the router uses 192.168.1.0/24, reserve 192.168.1.50 for the NAS via DHCP MAC binding. Replace example IPs with your actual values.

Create the Storage Mount Point

If only the system disk exists, use its free space at /srv/nas and proceed to Samba. For a dedicated data disk (already formatted ext4, not mounted), mount it by UUID to /srv/nas:

sudo mkdir -p /srv/nas
sudo cp -a /etc/fstab /etc/fstab.nas.bak
sudoedit /etc/fstab

Append to /etc/fstab (replace YOUR_UUID):

UUID=YOUR_UUID /srv/nas ext4 defaults,nofail 0 2

Verify and mount:

sudo findmnt --verify --verbose
sudo systemctl daemon-reload
sudo mount /srv/nas
findmnt --mountpoint /srv/nas

Confirm the output shows the correct partition and mount point. UUID ensures stability if device names change. Warning: formatting erases data; back up first.

Independent ext4 data disk mounted via UUID to /srv/nas, with /srv/nas/share as the Samba share directory.
Independent ext4 data disk mounted via UUID to /srv/nas, with /srv/nas/share as the Samba share directory.

Data disk persistently mounted; Samba will share /srv/nas/share.

Install Samba and Create a Dedicated Share Account

Samba provides SMB file sharing. Create a nasusers group for collaborative file management and a dedicated nasuser account:

sudo apt update
sudo apt install -y samba smbclient ufw

sudo groupadd nasusers
sudo useradd -M -g nasusers -s /usr/sbin/nologin nasuser
sudo install -d -m 2770 -o root -g nasusers /srv/nas/share
sudo smbpasswd -a nasuser

The last command sets the SMB password. The system account is locked (shell nologin). Directory mode 2770 (setgid) lets group members access and ensures new subdirectories inherit the nasusers group. Add more users by repeating useradd and smbpasswd with different names.

Configure the Share and Access Scope

Backup and edit the Samba config:

sudo cp -a /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudoedit /etc/samba/smb.conf

In the [global] section, set SMB2+ over TCP 445 and restrict to the LAN subnet:

server min protocol = SMB2_02
smb ports = 445
hosts allow = 127.0.0.1 192.168.1.0/255.255.255.0
hosts deny = ALL

Add a share named files at the end:

[files]
path = /srv/nas/share
browsable = yes
guest ok = no
read only = no
valid users = @nasusers
force group = nasusers
create mask = 0660
force create mode = 0660
directory mask = 2770
force directory mode = 2770
guest ok = no

blocks anonymous access; valid users limits to the group. File/directory masks give group members read-write; new items inherit the group. Private data should get its own share and access group.

nasuser logs in with Samba password; account belongs to nasusers group, Linux directory group is nasusers with 2770 permissions, enabling read-write.
nasuser logs in with Samba password; account belongs to nasusers group, Linux directory group is nasusers with 2770 permissions, enabling read-write.

Share access requires passing both Samba and Linux filesystem permission checks.

Systemd Override for Dedicated Data Disk

If using a separate data disk, ensure Samba waits for it to mount so files aren't written to the system disk by accident: sudo systemctl edit smbd.service Insert:

[Unit]
RequiresMountsFor = /srv/nas
ConditionPathIsMountPoint = /srv/nas

Skip this if using the system disk only.

Firewall Configuration

On a fresh install, allow only the LAN subnet to TCP 445. If managing via SSH, open your management IP/port before enabling:

sudo ufw default deny incoming
sudo ufw allow from 192.168.1.0/24 to any port 445 proto tcp
sudo ufw enable
sudo ufw status verbose

Validate and Start Samba

sudo testparm -s
sudo systemctl enable smbd
sudo systemctl restart smbd
smbclient //127.0.0.1/files -U nasuser -c 'ls'

Enter the Samba password; a directory listing confirms local share access.

Access from Windows, macOS, and Linux

Connect clients to the same LAN. Use these addresses (replace IP):

Windows: \192.168.1.50\files macOS: smb://192.168.1.50/files Linux: smb://192.168.1.50/files Windows: paste address in Explorer address bar or map as network drive. macOS: Finder → Command+K → enter smb:// address. Linux: use any SMB-capable file manager. Create a test file on one machine, edit from another; successful read-write means the NAS is operational.

Troubleshooting Connection and Write Issues

If connection fails, verify client and NAS are on the same subnet, then check:

systemctl status smbd --no-pager
sudo ss -ltnp 'sport = :445'
sudo ufw status verbose

If login works but writes fail, inspect mount point, user groups, and directory permissions. For a dedicated data disk, confirm it mounted after reboot:

findmnt --target /srv/nas/share
id nasuser
ls -ld /srv/nas/share
df -h /srv/nas/share

Long-Term Operational Considerations

Gigabit Ethernet caps at ~125 MB/s theoretical; real throughput depends on disk, Wi-Fi, and protocol overhead. An idle old PC at 20 W running 24/7 consumes ~14.4 kWh/month; cost depends on local electricity rates.

Back up critical data regularly to a separate disk, keep multiple dated versions, and test restores occasionally. RAID handles disk failures but not accidental deletion or whole-device loss — independent backups are still essential.

This setup is LAN-only; keep router port 445 closed to the internet. For remote access, use an authenticated VPN into the home network.

Start with basic photo/document sharing, ensure stability, then expand disks and features as needs grow.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSystem AdministrationNASSMBFile SharingSambaHome ServerUbuntu Server
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.