Mount an NFS share as non root user in cli

My /etc/exports

/root/backup       192.168.30.26(rw,sync,insecure,all_squash,no_subtree_check)

While I mounting as non root user,

mount -o v3 192.168.30.26:/root/backup /usr/backup/

I got mount: only root can do that

Note: I saw option user in fstab. Is there anyway without it ?


Users could modify system's mount table either by

  • using sudo or su

or by

  • having one entrie with user,noauto options, in /etc/fstab

Sample:

  • server side

    If on server host whith IP address 192.168.30.11, you have in /etc/exports

    /srv/share 192.168.30.26(rw,sync,insecure,all_squash,no_subtree_check)
    
  • client side

    On client host, with IP address 192.168.30.26 you have to add in /etc/fstab something like:

    192.168.30.11:/srv/share   /usr/backup    nfs    rw,relatime,user,noauto   0   0
    

Then, users on 192.168.30.26 must be able to mount share by just running:

mount /usr/backup

without sudo.

  • noauto prevent system to mount the share at boot time.
  • user tell system to autorize (local) users to mount the share.

Adapted from How to mount NFS share as a regular user - by Dan Nanni:

In order to allow a regular user to mount NFS share, you can do the following.

On the NFS client host (e.g., 10.1.1.20), update /etc/fstab as root.

$ sudo vi /etc/fstab

192.168.30.26:/root/backup /usr/backup nfs rw,noauto,user 0 0
                                                     ^^^^

In the above, "user" 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 non-permanently (which is not persistent across reboots):

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

If you want to enable export permanently (which is persistent across reboots):

 $ sudo vi /etc/exports

 /export 192.168.30.26(rw,async,no_root_squash,no_subtree_check)

 $ sudo exportfs -a

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

 $ mount /usr/backup

That why people have invented automounter. On a RPM based system:

as root

$ yum install autofs
$ systemctl enable --now autofs

as regular user

$ cd /net/<hostname>

where hostname is the name of the server.

Note: there is no need for en explicit mount. The autofs daemon will mount transparently as soon as user changes into that directory.