- 1 1. What Are the Benefits of Building a File Server on Ubuntu?
- 2 2. Comparing File-Sharing Methods: Differences Between Samba and NFS
- 3 3. [Samba] How to Build a File Server on Ubuntu
- 4 4. [NFS] How to Build a File Server on Ubuntu
- 5 5. Security and Operational Best Practices
- 6 6. Common Issues and How to Fix Them (Troubleshooting)
- 7 7. FAQ: Frequently Asked Questions About Ubuntu File Servers
- 8 8. Summary: Build a Flexible File-Sharing System With Ubuntu
1. What Are the Benefits of Building a File Server on Ubuntu?
What Is a File Server?
A file server is a server that allows multiple devices on a network to store and share common files. It streamlines file exchange within home or office networks, enables centralized data management, simplifies backups, and offers many additional advantages.
For example, if multiple people need to edit the same document, saving it on a file server allows everyone to access the latest version, rather than exchanging files saved on local PCs. It also reduces the risk of storing important data on individual machines and serves as an effective safeguard against data loss.
Why Choose Ubuntu?
Many operating systems can be used to build a file server, but Ubuntu is one of the most popular choices for the following reasons:
1. Free to Use
Ubuntu is an open-source Linux distribution, meaning it requires no licensing fees. This makes it a highly attractive option for individuals or organizations wanting to build a server environment while keeping costs low.
2. Lightweight and Highly Stable
Ubuntu consumes few system resources and can run on older PCs or devices like Raspberry Pi. Choosing an LTS (Long Term Support) version provides long-term security updates and bug fixes, making it ideal for server use.
3. Rich Support for Tools Like Samba and NFS
Ubuntu makes it easy to install and configure network file systems such as Samba (for Windows file sharing) and NFS (for Linux/Unix file sharing). With abundant packages and documentation, even beginners can build a server with confidence.
4. Large Community and Extensive Documentation
Because Ubuntu is widely used around the world, you can easily find solutions online when issues arise. Extensive documentation in English and other languages makes the platform friendly even for users who are not comfortable with English.
Perfect for Home or Small Office Environments
A file server built with Ubuntu is ideal for sharing data across multiple devices in a home network or for collaborative work in a SOHO environment. Compared to purchasing a dedicated NAS device, Ubuntu lets you create a more flexible and cost-effective solution tailored to your needs.
Here are some example use cases:
- A media server for sharing photos and videos across the household
- Sharing invoices, quotes, and documents in a small business
- Exchanging code and documentation within a development team
2. Comparing File-Sharing Methods: Differences Between Samba and NFS
When building a file server on Ubuntu, the two primary options are Samba and NFS. Both allow file sharing over a network, but they differ in supported client OS and functional characteristics. This section compares the features of each method to help you decide which one fits your environment.
What Is Samba? — Excellent Compatibility With Windows
Samba implements the Windows file-sharing protocol SMB (Server Message Block) on Linux. Installing Samba on Ubuntu allows you to create a file server that Windows PCs can access just like a network drive.
Features of Samba
- Excellent compatibility with Windows
- Easy access to shared folders via Windows Explorer
- Granular configuration of user authentication and permissions
- GUI-based configuration tools (e.g., Webmin) are available
When Samba Is the Best Choice
- When sharing files with Windows clients
- When sharing files between different OS platforms (e.g., Windows + Linux)
- When a user-friendly setup is preferred in home or office scenarios
What Is NFS? — Fast File Sharing for Linux/Unix Systems
NFS (Network File System) is a protocol mainly used for file sharing between Linux and Unix systems. From the client’s perspective, an NFS server’s folder behaves almost like a local directory.
Features of NFS
- Ideal for Linux-to-Linux file sharing
- Lightweight and high-speed performance
- Simple configuration suitable for large-scale sharing
- Requires careful security configuration (IP-based access control)
When NFS Is the Best Choice
- Linux-based server environments
- Shared server directories for development teams
- Scenarios requiring lightweight and high-speed file transfers
Comparison Table: Samba vs. NFS
| Item | Samba | NFS |
|---|---|---|
| Supported OS | Windows / Linux / macOS | Linux / Unix (Windows not recommended) |
| Protocol | SMB (CIFS) | NFS |
| Speed | Medium (varies by configuration) | High |
| Security | User authentication, encryption supported | IP-based control, Kerberos support |
| Configuration Difficulty | Moderate | Simple |
| Use Case | Cross-platform sharing | Efficient Linux-to-Linux sharing |
Which Should You Choose?
Ultimately, the choice depends on client OS, use case, and priorities:
- Samba is best when sharing with Windows clients
- NFS is best for Linux-to-Linux high-speed sharing
- For mixed environments, using both Samba and NFS is also a valid approach
Ubuntu’s flexibility allows you to combine both based on your needs.
3. [Samba] How to Build a File Server on Ubuntu
In this section, we explain how to install and configure Samba on Ubuntu to build a file server. This method is especially effective when sharing files with Windows clients.
Preparation: Update Ubuntu and Check Installed Packages
First, update your Ubuntu system to the latest version. Open a terminal and run the following commands:
sudo apt update
sudo apt upgradeNext, check whether Samba is already installed:
smbclient --versionIf no version is shown, install Samba in the next step.
How to Install Samba
Install the Samba package using the following command:
sudo apt install samba -yAfter installation, verify that the service is active:
sudo systemctl status smbdIf it displays “active (running)”, Samba is running correctly.
Configuring smb.conf and Creating a Shared Folder
The Samba configuration file is located at /etc/samba/smb.conf. First, create a shared directory. In this example, we use /srv/samba/shared as the shared folder.
sudo mkdir -p /srv/samba/shared
sudo chmod 777 /srv/samba/sharedNext, edit the configuration file:
sudo nano /etc/samba/smb.confAdd the following configuration at the end of the file:
[Shared]
path = /srv/samba/shared
browseable = yes
read only = no
guest ok = yesThis configuration creates a public folder writable by anyone. For secure use, configure user authentication as described later.
Apply the settings by restarting Samba:
sudo systemctl restart smbdCreating Samba Users and Setting Access Permissions
To enhance security, it is recommended to create Samba users and restrict access.
- Create a local Ubuntu user (skip if it already exists):
sudo adduser sambauser- Register the user as a Samba account:
sudo smbpasswd -a sambauser- Change the directory ownership and restrict access:
sudo chown sambauser:sambauser /srv/samba/shared
sudo chmod 770 /srv/samba/shared- Modify smb.conf to require authentication:
[SecureShared]
path = /srv/samba/shared
browseable = yes
read only = no
valid users = sambauserHow to Connect From a Windows Client
Once Samba is set up, you can connect from a Windows PC using these steps:
- Open File Explorer
- Enter the following in the address bar:
\\<Ubuntu-server-IP>\Shared - When prompted, enter the username and password for
sambauser
If successful, the shared folder will function just like a regular directory on Windows.
4. [NFS] How to Build a File Server on Ubuntu
NFS (Network File System) is a lightweight and fast network file-sharing protocol widely used in Linux and Unix environments. It is easy to install on Ubuntu and enables smooth file exchange between multiple Linux machines.
Here, we walk through the steps to set up an NFS server on Ubuntu.
How to Install the NFS Server
Install the NFS server package by running the following commands on the Ubuntu server:
sudo apt update
sudo apt install nfs-kernel-server -yVerify that the service is running:
sudo systemctl status nfs-serverIf it shows “active (running)”, the installation was successful.
Configuring /etc/exports and Defining Shared Directories
Next, create a directory you want clients to access. In this example, we use /srv/nfs/shared:
sudo mkdir -p /srv/nfs/shared
sudo chown nobody:nogroup /srv/nfs/shared
sudo chmod 755 /srv/nfs/sharedEdit the NFS configuration file:
sudo nano /etc/exportsAdd the following line (replace 192.168.1.0/24 with your network):
/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)Apply the settings:
sudo exportfs -a
sudo systemctl restart nfs-serverNFS server setup is now complete.
How to Mount From a Linux Client
On each Linux client that will access the NFS server, install the NFS client package:
sudo apt update
sudo apt install nfs-common -yCreate a mount point such as /mnt/nfs_shared:
sudo mkdir -p /mnt/nfs_sharedThen mount the NFS share:
sudo mount -t nfs 192.168.1.10:/srv/nfs/shared /mnt/nfs_shared※ Replace 192.168.1.10 with your NFS server’s IP address.
Once mounted, the shared directory behaves like a local folder.
Auto-Mount on Boot (Optional)
To mount the NFS share automatically on startup, add this line to /etc/fstab:
192.168.1.10:/srv/nfs/shared /mnt/nfs_shared nfs defaults 0 0This ensures the NFS share mounts automatically at boot.
NFS-Specific Access Restrictions and Important Notes
NFS uses IP-based access control, unlike Samba. In /etc/exports, always specify only trusted networks or hosts.
Additionally, if the UID (User ID) and GID (Group ID) on the server and client do not match, file ownership may not be interpreted correctly. For smooth operation, it is advisable to use matching UIDs and GIDs across systems.
With this, your Ubuntu NFS file server is ready. Compared to Samba, NFS is simpler and faster, making it highly suitable for Linux environments.

5. Security and Operational Best Practices
While a file server is a powerful tool for sharing data over a network, it also increases the risk of data leaks and unauthorized access if proper security measures are not implemented. This section introduces essential security and management best practices for running an Ubuntu file server safely and efficiently.
Restrict Access With the Firewall (ufw)
Ubuntu includes a built-in firewall called ufw (Uncomplicated Firewall). For Samba- or NFS-based file sharing, you can limit unnecessary network traffic by explicitly allowing only the required ports.
Example: Allowing Ports for Samba
sudo ufw allow SambaThis command opens all ports required for Samba (137, 138, 139, 445) at once.
Example: Allowing Ports for NFS
NFS ports vary depending on the environment, so you may need to open them individually or configure them to use fixed ports.
sudo ufw allow from 192.168.1.0/24 to any port nfs※ 192.168.1.0/24 represents the allowed network range.
Strengthen Access Control and User Authentication
Samba Access Restrictions
- Use
valid usersto restrict who can access each share - Use
read only = yesto allow read-only access when needed - Use
hosts allowandhosts denyfor IP-based restrictions
Example (smb.conf):
[SecureShared]
path = /srv/samba/secure
read only = no
valid users = user1
hosts allow = 192.168.1.NFS Access Restrictions
- Specify allowed IP addresses or networks in
/etc/exports - Explicitly define
rw(read/write) orro(read-only) - Use
root_squashto prevent clients from using root privileges
Example:
/srv/nfs/secure 192.168.1.0/24(rw,sync,no_subtree_check,root_squash)Monitor Logs and Detect Irregularities
Monitoring logs is essential for detecting unauthorized access, errors, or suspicious activity.
- Samba logs:
/var/log/samba/log.smbd - NFS logs:
/var/log/syslogorjournalctl -u nfs-server
Using tools like fail2ban allows you to automatically block IP addresses after repeated login failures.
Build an Automated Backup System
Regular backups are essential to protect against accidental deletion, corruption, or hardware failure.
Backup Examples
- Differential backup using
rsync - Scheduled backups using
cron - Storing backups on external HDDs or NAS
- Syncing with cloud storage (Google Drive, Dropbox) using
rclone
Example: A cron job that backs up daily at 2:00 AM
0 2 * * * rsync -a /srv/samba/shared/ /mnt/backup/shared/Keep Software Updated Regularly
Regular updates are one of the most effective ways to prevent security vulnerabilities.
sudo apt update && sudo apt upgrade -yUsing an LTS version of Ubuntu ensures long-term access to security updates and stability.
Running a file server is not a one-time setup. For stable operation, you must consistently manage security, backups, and maintenance.
6. Common Issues and How to Fix Them (Troubleshooting)
Even after setup, file servers may experience configuration issues or operational problems. This section summarizes common issues with Samba and NFS file servers on Ubuntu and how to resolve them.
Cannot Connect / Shared Folder Not Visible
Symptoms
- Windows or Linux clients cannot access shared folders
- The server does not appear in the network list
Main Causes and Solutions
| Cause | Solution |
|---|---|
| Firewall blocking traffic | sudo ufw allow Samba or sudo ufw allow from [IP] to any port nfs |
| Hostname resolution failure | Access using IP directly: \\192.168.1.10\Shared |
| Samba/NFS service is not running | sudo systemctl restart smbd or restart nfs-server |
| Incorrect client network settings | Check subnet mask, gateway, and DNS settings |
Permission Errors
Symptoms
- Cannot create or modify files
- “Access denied” messages appear
Main Causes and Solutions
| Cause | Solution |
|---|---|
| Incorrect directory ownership | sudo chown -R user:group /shared-folder |
| Insufficient permissions (chmod) | sudo chmod -R 770 /shared-folder |
| Misconfigured Samba settings | Ensure read only = no in the [shared] section |
| UID/GID mismatch in NFS | Align user IDs between server and client (id command) |
Mount Not Persisting / Shared Folder Disappears After Reboot
Symptoms
- NFS-mounted shared folders disappear after the client reboots
- The mount command needs to be run manually each time
Main Causes and Solutions
| Cause | Solution |
|---|---|
| Missing fstab entry | Add auto-mount settings to /etc/fstab |
| Network initializes later than fstab | Add nofail,_netdev to mount options |
| Slow response from server | Add timeout settings such as timeo=14 when mounting |
Example fstab entry (for NFS):
192.168.1.10:/srv/nfs/shared /mnt/nfs_shared nfs defaults,_netdev,nofail 0 0Files Not Visible / Changes Not Synced
Symptoms
- Files saved from another client do not appear immediately
- Changes take time to reflect across devices
Main Causes and Solutions
| Cause | Solution |
|---|---|
| Cache delay | Often temporary—refresh (Ctrl + F5) or reconnect |
| Client-side buffering (NFS) | Use actimeo=0 for immediate sync |
| Delayed write operations (Samba) | Add strict sync = yes to smb.conf |
Checking Logs for Diagnosis
When investigating issues on Ubuntu, checking log files is essential.
Samba Logs
cat /var/log/samba/log.smbdNFS Logs
journalctl -u nfs-serverLogs contain information about failed access attempts, authentication errors, and configuration issues. Searching error messages online usually leads you to relevant solutions.
Tips for Effective Troubleshooting
- Change settings in small steps and test each change
- Always back up configuration files
- Use validation tools such as
testparmandexportfs -v - Restart services or reload configuration after making changes
7. FAQ: Frequently Asked Questions About Ubuntu File Servers
This section covers common questions and concerns beginners and intermediate users encounter when building and operating Ubuntu file servers.
Q1. Should I use Samba or NFS?
A. Choose based on the client operating system.
- Samba (SMB) for Windows environments
Easy access through File Explorer - NFS for Linux-to-Linux sharing
Lightweight, fast, and stable
You can also use both in mixed environments—there is no need to limit yourself to only one.
Q2. How do I share an external storage device (USB HDD)?
A. Mount the external storage device first, then configure Samba or NFS to share the mounted directory.
- Check available devices:
lsblk- Create a mount point and mount the device:
sudo mkdir /mnt/usb
sudo mount /dev/sdX1 /mnt/usb- Then configure Samba or NFS to share
/mnt/usb.
If you want it to mount automatically, add an entry in /etc/fstab.
Q3. I cannot connect to Samba from Windows 11.
A. The issue may be related to SMB protocol versions or authentication.
Try adding the following to /etc/samba/smb.conf:
client min protocol = SMB2
server min protocol = SMB2- Avoid guest access—use username/password instead
- If SMB 1.0 is enabled on Windows, consider disabling it for security reasons
Q4. How should I back up my file server?
A. Automating backups is the most reliable approach.
- Differential backups using
rsync - Scheduled tasks using
cron - Backup to external HDD or NAS
- Sync with cloud services using
rclone
Example crontab job (runs daily at 2 AM):
0 2 * * * rsync -a /srv/samba/shared/ /mnt/backup/Q5. Which is better for a file server: Ubuntu Desktop or Ubuntu Server?
A. Ubuntu Server for stable long-term operation; Ubuntu Desktop for ease of use.
| Item | Ubuntu Server | Ubuntu Desktop |
|---|---|---|
| GUI availability | No (lightweight) | Yes (beginner-friendly) |
| Resource usage | Low | Higher |
| Operation style | Command-line focused | GUI operations possible |
| Recommended use | Full-scale server environments | Home use, learning, lightweight setups |
If you do not need a GUI, Ubuntu Server tends to be more secure and resource-efficient.
8. Summary: Build a Flexible File-Sharing System With Ubuntu
Building a file server on Ubuntu is an excellent choice for creating a cost-efficient, stable, and customizable file-sharing environment. This guide covered the differences between Samba and NFS, step-by-step setup instructions, security practices, troubleshooting methods, and more.
Choose Samba or NFS Based on Your Use Case
Select the file-sharing method according to your needs:
- Samba for Windows file sharing — direct access from File Explorer
- NFS for Linux-to-Linux high-speed sharing — lightweight and efficient
You can also combine both for mixed environments.
Focus on Security and Maintainability
- Configure firewalls and access restrictions
- Maintain system health with regular updates and log monitoring
- Implement automated backups to prepare for failures
Why Build a Custom File Server?
While purchasing a NAS is an option, creating your own server with Ubuntu provides:
- A simple system with only the features you need
- Flexibility in hardware and storage capacity
- Valuable skills for both personal learning and business applications
If the process seemed difficult at first, we hope this guide helped demonstrate that building your own file server is entirely within reach.
Ubuntu allows you to create a powerful and versatile file server environment suitable for everything from home use to professional applications. Choose the setup that best fits your network and workflow.


