Running NFS shares on a VPS is an efficient way to centralize backups and media storage across multiple Linux servers. With a secure NFS Server on VPS infrastructure, you can share folders just for backups and media, and make sure only specific and trusted servers are allowed to access them.
In this guide from PerLod Hosting, you will learn to build a secure NFS setup, from the basic installation to hardened exports designed specifically for backups and media.
When to Use an NFS Server on VPS?
It is important to know whether NFS is actually good to use for your VPS setup or not. In this step, we want to explore the situations where NFS on a VPS works well, and the cases where you should avoid it or choose a different method.
You can use NFS when:
You have Linux backup or media servers that need a shared network filesystem.
You control both the VPS and the client over a VPN or a private network.
Avoid using NFS when:
You must expose it directly to the public internet. It has a security risk.
You need Windows sharing. You can use SMB instead.
Tip: If you need a dedicated node just for storage, you can use a Storage VPS and keep NFS traffic on a private network only.
Prerequisites for Setting up NFS Shares on VPS
Before starting the NFS server setup, make sure to meet these requirements:
Server: An Ubuntu 22.04 or 24.04 VPS with root or sudo access.
Client: A Linux system like Ubuntu, Debian, or a RHEL-based distro.
Network: A private network or VPN connection between the VPS and the client. It is strongly recommended for NFS security.
Once you are done, proceed to the following steps to set up the NFS server on VPS.
Install NFS Server
On your Ubuntu VPS, run the system update with the command below:
Bash
sudoaptupdate&&sudoaptupgrade-y
Use the command below to install the NFS server:
Bash
sudoaptinstallnfs-kernel-server-y
This command installs the core NFS server tools.
Create NFS Share Directories
At this point, you must decide what folders you actually want to share with the network. We want to create two dedicated directories on the VPS, one for backups and one for media:
/mnt/nfs/backups: For backup jobs such as restic, borg, rsync, etc.
/mnt/nfs/media: For media libraries such as Plex, Jellyfin, etc.
The chown nobody:nogroup changes ownership to a non-privileged user and group. It follows common NFS security guidelines by preventing remote root users from having full root access on the server.
Configure NFS Exports
At this point, you must define which directories to share, who can access them, and their permission levels.
Edit the default configuration file for the NFS server:
Bash
sudonano/etc/exports
Add the following lines to the file and replace the CLIENT_IP with your actual client server's IP address:
The mount -t nfs specifies the filesystem type as NFS and maps the remote server's directory to your local client directory.
Make NFS Mounts Persistent with fstab
In this step, you can add your NFS mounts to /etc/fstab, so they automatically mount after a reboot. This prevents your backup and media paths from disappearing when the client server restarts.
Edit the filesystem table:
Bash
sudonano/etc/fstab
Add these lines at the bottom of the file with your NFS server's IP:
Once you are done, save and close the file. Verify the fstab configuration without rebooting with the command below:
Bash
sudomount-a
This attempts to mount all filesystems listed in /etc/fstab. If the command returns no output, your configuration is correct and active.
Conclusion
At this point, you have a secure NFS share setup for an NFS server on VPS, with separate exports for writable backups and safer read-only media. The key is to keep exports clean in /etc/exports and restrict access to trusted clients only.
We hope you enjoy this guide. Subscribe to our X and Facebook channels to get the latest updates and articles.
It prevents a client's root user from having root access on the server by remapping them to a low-privilege user.
Check your /etc/fstab file and ensure you added _netdev. This tells the system to wait for the network to connect before trying to mount the shares. Test your fstab file with sudo mount -a to catch errors without restarting.
NFS uses UIDs and GIDs to control access. If they don't match between server and client, access gets blocked. Make sure the same UIDs/GIDs exist on both machines. Also note that root_squash prevents the client's root from having root access on the server.
We use cookies to run PerLod and to understand how the site is used. You can accept everything, or open Manage to turn individual categories off. Cookie policy.