How to mount NFS share as a regular user

Last updated on October 15, 2020 by Dan Nanni

If you are a non-root regular user and attemp to mount a remote NFS share, you will get the following error:

mount: only root can do that

In order to allow a regular user without root privilege to mount a remote home directory via NFS, you can do the following.

On the NFS client host (e.g., 10.1.1.20), update /etc/fstab as root. I assume that the user requiring NFS mount is alice.

$ sudo vi /etc/fstab
10.1.1.10:/export/alice /home/alice/Desktop/mnt nfs rw,noauto,user 0 0

In the above configuration, the user option allows a non-root user to mount, and noauto means no automatic mount on boot.

On the NFS server host (e.g., 10.1.1.10), enable export for the client as root.

If you want to enable export temporarily one time (which is not persistent across reboots):

$ sudo exportfs 10.1.1.20:/export -o rw,async,no_root_squash,no_subtree_check

If you want to enable export permanently (which is persistent across reboots), edit /etc/exports as follows.

$ sudo vi /etc/exports
/export 10.1.1.20(rw,async,no_root_squash,no_subtree_check)

Finally, run this command:

$ sudo exportfs -a

Now you can log in as alice on the NFS client host, and do NFS mount as follows.

$ mount /home/alice/Desktop/mnt

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (BTC Wallet: 1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Xmodulo © 2020 ‒ About ‒ Powered by DigitalOcean