Simple File Sharing over NFS

  • Service Provider

    In the UNIX world, NFS is the simplest means of handling file sharing between systems. And working with NFS on Linux is incredibly easy too. Details on exporting NFS files is handled by the aptly named /etc/exports file. In this file we list the folder to export, the host(s) allowed to mount this exported share and any options on that share (like read-only and root squash restrictions.)

    In our example here we will take the local folder, /var/data


    In this example, /var/data on our local server is being shared out to the host named “garfield” with the options of “rw”, for read-write (use ro for read-only) and “root_squash.” Root squashing requires a little explanation. This is a standard security procedure for NFS as it stops foreign hosts from acting as the root and gaining unlimited control of your file share. Basically anyone claiming to be root on the foreign system gets least privilege access, rather than most privilege access, to the share. It is rare that you would want to not have this option in place.

    To cause the NFS service to re-read the /ext/exports file and enact the changes there we run the following command:

    # exportfs -a

    At this point you have a working NFS export and you should be able to mount it from the host names “garfield” without any problem, we hope.

    Originally posted in 2012 on my Linux blog: