# How to Share Files Between macOS and Linux using NFS (Network File System)
When working in a mixed OS environment containing both Macs and Linux servers, sharing files efficiently is a critical requirement.
While Server Message Block (SMB/CIFS) is the dominant protocol for Windows networking, its performance and permission handling can sometimes be erratic when communicating between UNIX-like systems. The Network File System (NFS) protocol is a native, high-performance alternative designed specifically for UNIX-to-UNIX communication.
Because both macOS and Linux are built on UNIX foundations, they inherently support NFS, offering incredibly fast transfer speeds, robust permission mapping, and minimal overhead.
This guide explains how to configure an Ubuntu Linux machine as an NFS Server and mount the shared directory on a macOS client machine.
## Prerequisites
1. An **Ubuntu Linux server** (acting as the NFS Host) with a static IP address on your local network (e.g., `192.168.1.50`).
2. A **macOS machine** (acting as the NFS Client) on the same local network.
3. Both machines must have network visibility to each other (no firewalls blocking internal traffic between them on port 2049).
## Step 1: Install and Configure the NFS Server on Linux
Connect to your Ubuntu server via SSH.
1. **Install the NFS Kernel Server package:**
“`bash
sudo apt update
sudo apt install nfs-kernel-server -y
“`
2. **Create the directory you wish to share:**
For this example, we will create a folder in the `/opt` directory.
“`bash
sudo mkdir -p /opt/shared_folder
“`
3. **Set directory permissions:**
To ensure the macOS client can read and write to the directory without complex UID/GID (User ID/Group ID) mapping configurations, we will temporarily set broad permissions. In a production environment, you should map specific user IDs.
“`bash
sudo chown nobody:nogroup /opt/shared_folder
sudo chmod 777 /opt/shared_folder
“`
4. **Configure the NFS Exports file:**
The `/etc/exports` file controls which directories are shared and which IP addresses are allowed to access them.
“`bash
sudo nano /etc/exports
“`
5. **Define the share:**
Add the following line to the bottom of the file. Replace `192.168.1.0/24` with your actual local subnet. This allows any machine on your local network to mount the share.
“`text
/opt/shared_folder 192.168.1.0/24(rw,sync,no_subtree_check)
“`
– **`rw`**: Grants read and write access.
– **`sync`**: Forces changes to be written to the disk immediately before completing the request, ensuring data integrity.
– **`no_subtree_check`**: Disables subtree checking, which improves reliability and performance when files are renamed or moved within the share.
6. **Apply the export configuration:**
Tell the NFS server to re-read the configuration file and apply the changes.
“`bash
sudo exportfs -a
“`
7. **Restart and enable the NFS service:**
“`bash
sudo systemctl restart nfs-kernel-server
sudo systemctl enable nfs-kernel-server
“`
8. **Adjust the Firewall (UFW):**
If you are running the Uncomplicated Firewall on your Ubuntu server, you must explicitly allow NFS traffic.
“`bash
sudo ufw allow from 192.168.1.0/24 to any port nfs
“`
## Step 2: Mount the NFS Share on macOS
macOS includes native support for mounting NFS volumes directly through the Finder or via the Terminal.
### Method A: Mounting via macOS Finder (Graphical Interface)
This is the easiest method for ad-hoc file transfers.
1. Switch to your Mac.
2. Open **Finder**.
3. In the top menu bar, click **Go > Connect to Server** (or press `Cmd + K`).
4. In the Server Address field, enter the NFS URL using your Linux server’s IP address and the absolute path to the shared folder.
`nfs://192.168.1.50/opt/shared_folder`
5. Click **Connect**.
6. The share will instantly mount as a network drive on your desktop and appear in the sidebar of Finder windows. You can now drag and drop files just like any local folder.
### Method B: Mounting via macOS Terminal (Persistent/Advanced)
If you require the mount to behave consistently for scripts, or if you need to pass specific mounting options to optimize performance, mounting via the Terminal is preferred.
1. Open the **Terminal** app on your Mac.
2. Create an empty directory to serve as the mount point. It is common practice to mount external drives in `/System/Volumes/Data/mnt` (or just your home directory for ease of use). We will use a folder on the Desktop.
“`bash
mkdir ~/Desktop/LinuxShare
“`
3. Execute the `mount` command. You must use `sudo` because mounting a network file system requires administrative privileges. We will pass advanced options (`-o resvport`) which is often required by macOS to connect to Linux NFS servers successfully.
“`bash
sudo mount -t nfs -o resvport,rw 192.168.1.50:/opt/shared_folder ~/Desktop/LinuxShare
“`
4. Verify the mount:
Type `df -h` in the terminal. You should see `192.168.1.50:/opt/shared_folder` listed in the output, showing its available capacity.
### Troubleshooting: “Operation not permitted” on macOS
If you receive an `Operation not permitted` or `Permission denied` error when trying to mount the share via the Terminal, the Linux NFS server is likely rejecting the connection because the macOS client is attempting to connect using an unprivileged port (a port higher than 1024).
The `-o resvport` flag in the terminal command above solves this by forcing macOS to use a privileged port (under 1024). If you are using the Finder UI (Method A) and it fails, you must configure the Linux server to accept insecure ports.
To do this, edit the `/etc/exports` file on the Linux server and append `insecure` to the options list:
“`text
/opt/shared_folder 192.168.1.0/24(rw,sync,no_subtree_check,insecure)
“`
Run `sudo exportfs -a` on Linux, and try connecting from the Mac Finder again.
## Unmounting the Share
When you are finished, it is important to unmount the share gracefully before disconnecting from the network.
– **If mounted via Finder:** Click the Eject icon next to the share in the Finder sidebar.
– **If mounted via Terminal:** Run the `umount` command against your local mount point:
“`bash
sudo umount ~/Desktop/LinuxShare
“`
By leveraging NFS, you bypass the overhead of SMB translation, resulting in lightning-fast, native UNIX file transfers between your Apple and Linux hardware.