Configure Secure NFS File Shares for Backups and Media

Updated on Apr 18, 2026
Mila H
5 MINS READ
Table of Contents
Set Up a Secure NFS Server on VPS

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
sudo apt update && sudo apt upgrade -y

Use the command below to install the NFS server:

Bash
sudo apt install nfs-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.
Bash
sudo mkdir -p /mnt/nfs/backupssudo mkdir -p /mnt/nfs/media

Set the correct ownership and permissions for the directories:

Bash
sudo chown nobody:nogroup /mnt/nfs/backups /mnt/nfs/mediasudo chmod 775 /mnt/nfs/backups /mnt/nfs/media

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
sudo nano /etc/exports

Add the following lines to the file and replace the CLIENT_IP with your actual client server's IP address:

Bash
/mnt/nfs/backups CLIENT_IP(rw,sync,no_subtree_check,root_squash)/mnt/nfs/media CLIENT_IP(ro,sync,no_subtree_check,root_squash)

Option explanations:

  • rw and ro: Allows Read and Write for backups and Read-Only for media to prevent accidental deletion.
  • sync: Forces changes to be written to disk before replying to the client, preventing data loss during crashes.
  • no_subtree_check: Disables subtree checking to improve reliability when files are renamed while open.
  • root_squash: Secures the server by mapping client root users to an unprivileged account (nobody).

Apply your configuration changes and restart NFS to apply the changes:

Bash
sudo exportfs -arvsudo systemctl restart nfs-kernel-serversudo systemctl enable nfs-kernel-server

Also, you must restrict access to your client's IP. To do this, you can use the following UFW rule:

Bash
sudo ufw allow from CLIENT_IP to any port nfssudo ufw enable

Install and Configure the NFS Client

Once you are done with setting up the NFS server on VPS, you can log in to your client machine to set up the connection.

We assume your client machine is an Ubuntu system. Run the system update, install the NFS client, and create the local mount points:

Bash
sudo apt updatesudo apt install nfs-common -ysudo mkdir -p /mnt/backups_clientsudo mkdir -p /mnt/media_client

Mount the NFS Shares

From the client machine, you can test the connection by mounting the shares manually. To do this, you can run the commands below:

Bash
sudo mount -t nfs SERVER_IP:/mnt/nfs/backups /mnt/backups_clientsudo mount -t nfs SERVER_IP:/mnt/nfs/media /mnt/media_client

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
sudo nano /etc/fstab

Add these lines at the bottom of the file with your NFS server's IP:

Bash
SERVER_IP:/mnt/nfs/backups /mnt/backups_client nfs defaults,timeo=900,retrans=5,_netdev 0 0SERVER_IP:/mnt/nfs/media /mnt/media_client nfs defaults,ro,timeo=900,retrans=5,_netdev 0 0

Once you are done, save and close the file. Verify the fstab configuration without rebooting with the command below:

Bash
sudo mount -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.

For further reading:

How to Set Up BorgBackup on a Storage VPS

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.