featured computer 850

NFS Setup: Basic Home File-server Linux to Linux Sharing

Updated 2017-02. Ubuntu 16.04 LTS.


This is a description of what I did to get linux-to-linux file sharing working on a home network where client computers get full access to files on the server without entering a username and password. This method does involve running a script once to mount (make available) the desired files on the server. This method allows you to work seamlessly with files on a central file server without browsing to network folders. I describe the process using Ubuntu Linux, which means it probably is applicable to Debian GNU/linux.

Install NFS Server and Client Software

me@myhost$ sudo apt-get install nfs-kernel-server

Using the command line (terminal), or install the Synaptic package manager and use its search feature to install the server software on your home file-server. The client machine only needs the “nfs-common” package, which contains the NFS client software. Not completely obvious to a new-comer, but now you know there is no “nfs-client” package.

Give Your Computers Fixed IP Addresses

The simplest way to do refer to your computers in a home or SOHO LAN is to use fixed IP addresses. You can give your computer a fixed IP address, even if you use DHCP on your router/wifi device. I give a description how to do this in a separate Fixed IP Addresses page. Put all the fixed IP addresses you are using in the /etc/hosts file per the example in the default file. I show an example /etc/hosts file on my Virtual Hosts page.

Modify the /etc/exports File

The real trick to making files available for NFS sharing is modifying the /etc/exports file. You can do this with a GUI tool by typing sudo gedit /etc/exports in a terminal and supplying the super-user password. The formatted text below is the complete content of a working file.

There is one line for each share. I am sharing most of the files from a single user’s home directory to 2 different clients (only one shown). I don’t include the “Downloads” folder so that I can keep it as the default in my web browser, independent of whether the other folders are mounted. Following the file (folder) to be shared, there is one entry for each client describing the conditions of the mount. For example, rw means both “read” and “write” permissions are given.

I added the “no_subtree_check simply to get rid of a notification message. I can’t explain why it’s there. It works without it. Note there is no whitespace within the parentheses or between them and the IP address. Including spaces will generate an error. The hash marks (pound signs) are for comments.

***This makes your files mountable in an insecure (writeable) fashion. Do not use for sensitive data.***

# /etc/exports: the access control list for filesystems which may be exported to NFS clients.
#  See exports(5).
# The user's name (USER) on the FILE-SERVER needs to be filled in.
# Listed are CLIENT machines fixed IP addresses (edit and add/subtract as needed).
# This file is sensitive to whitespace within each entry

Creating Mount Points on the Client Machines

In the home directory of your client machines you MAY need to create folders (a.k.a. mount points) so your computer knows where to put the locations of all the files you have access to on the fileserver. I happen to use most of the same name in both places, but that is not necessary. You may be happy with the default folders that Ubuntu supplies. In my case, I add a folder “Voice” for spoken word recordings and “public_hmtl” for website development.

Mounting the Shares from Client Machines

There is a way you can have shares automatically mounted via NFS, but for a home network it probably more trouble than it’s worth. I double-click the “mountem.sh” file below and choose “Run In Terminal”. Then I need to enter the super-user password once. The “mounting” of all shares takes about 1 second. No files are actually transferred to the client. The folders stay mounted until one of the comptuers is turned off.

Below is the content of the mountem.sh script, with both the server and client usernames left for you to fill in. You would need to edit the fixed IP in this script, which is the IP address of the SERVER, and both the server and remote user names. It is a plain text file that should be kept in your home directory and made executeable chmod u+x mountem.sh.

# File to mount NFS directories (folders) for WRITEABLE access.
# To use, update the FIXED IP of server and both USER NAMES.
sudo mount    /home/UREM/Documents -o rw
sudo mount        /home/UREM/Music -o rw
sudo mount     /home/UREM/Pictures -o rw
sudo mount       /home/UREM/Videos -o rw
#sudo mount /home/UREM/Websites -o rw

Once the software is installed and the two files listed above are set up, there is only about 5 seconds worth of effort each time you want to access your files. They are unreachable in the meantime, in the case you do want to keep others from accessing them.

Similar Posts