I have an Ubuntu 20.04 server (a local VM in my case). How do I mount a directory on the Linux server from a macOS Catalina client, using NFS?
1 Answer
Setting up the Linux server
Install the NFS server as per the Ubuntu NFS guide:
sudo apt install nfs-kernel-serverEdit
/etc/exports:sudo nano /etc/exportsNow add a line similar to this:
/home/ubuntu 172.16.238.0/24(insecure,rw,all_squash,anonuid=1000,anongid=1000,no_subtree_check)/home/ubuntuis the directory to export172.16.238.0/24is the IP addresses to accept connections from. The Mac client's IP address should be in this range. Use*to allow from any IP address. (But be careful not to make your NFS server available to the entire internet!)insecuremeans to accept connections from unprivileged (higher) port numbersrwmeans read-writeall_squash,anonuid=1000,anongid=1000forces all reads and writes to be performed by the user/group with UID/GID 1000 (1000 is the defaultubuntuuser/group on my server). Run theidcommand on the server to find out your UID/GID. You need these options unless your Ubuntu server and Mac client use the same UID/GID for the main user.no_subtree_checkis a performance thing
Save the file and run
sudo exportfs -vrato reload the NFS exports. (I'm not sure if the
-aoption is necessary.)
Setting up the Mac client
On the macOS client, edit the
/etc/auto_masterfile (documented in theauto_master man page):sudo nano /etc/auto_masterand change the line starting with
/netto the following (or add it if necessary):/net -hosts -nobrowse,nosuid,locallocks,nfc,actimeo=1locallockscreates locks on the client rather than on the server. Without this, Finder becomes very slow and takes forever to show directories.nfcmakes UTF-8 file names workactimeo=1sets the attribute cache timeout as short as possible. Note that setting it to0(or addingnoac) causes Finder not to notice when a file is deleted on the server, so we can't use it.- Note that we're not using
nfsvers=4here. I got kernel panics on the Mac with this, so I went back to the default (NFSv3).
Note: It appears that some macOS software updates can overwrite this file and remove your changes. I've found myself having to go back to back to this answer once a year or so re-apply the changes.
Refresh the automounts by running
sudo automount -vc(If you previously tried to mount an NFS volume, unmount it first, like so:
sudo umount -f /net/fileserver.local/home/ubuntu)In the Finder menu, select Go -> Go to Folder, and type
/net/SERVER_HOST_NAME, e.g./net/fileserver.local.You should find your exported directory in there, e.g. at
/net/fileserver.local/home/ubuntu. Drag this directory to the Finder sidebar to make it easy to access in the future.
-
Also, is there any way to fix the permissions. The only way I have to access my files from the Mac is giving 777 permissions to the folder I want to share :( otherwise the system shows me a message telling my I don't have permissions to browse the folder.Carlos Vega– Carlos Vega2015-09-04 20:08:23 +00:00Commented Sep 4, 2015 at 20:08
-
@carlosvega The
all_squash,anonuid=1000,anongid=1000options take care of permissions for me - everything owned by UID 1000 on the Ubuntu server can be accessed from the Mac client no problem, so there's no need for chmodding to 777.Jo Liss– Jo Liss2015-09-07 14:34:41 +00:00Commented Sep 7, 2015 at 14:34 -
6Just a quick comment, if you just want to mount "on the fly" on the mac side, this works for me :
sudo mount -t nfs -o resvport 172.16.238.x:/home/ubuntu /Users/xyz/ubuntuScott Carlson– Scott Carlson2015-09-09 23:13:02 +00:00Commented Sep 9, 2015 at 23:13 -
works for me with Mac OSX Sierra and Ubuntu 16.04Antonios Hadjigeorgalis– Antonios Hadjigeorgalis2016-11-17 18:26:46 +00:00Commented Nov 17, 2016 at 18:26
-
3People don't realize how much trial and error lies behind this brilliant answer. Especially the "nfc" part is CRUCIAL when mounting (or
rsyncing) non-MacOS servers. You won't notice at first, but the UTF-8 ain't the same on OS X as it is everywhere else. Without it, your file names might very well be garbled and require hours on end to fix later on. I know I can't use a comment to say, "thank you," so I'll just end it here ;)FlamingKitties– FlamingKitties2016-12-05 13:43:05 +00:00Commented Dec 5, 2016 at 13:43