9

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 ?

1
  • 2
    Yes, only root could specifiy options to mount command, you have to run mount with only target from fstab as argument: mount /usr/backup. Jan 10, 2017 at 7:31

5 Answers 5

7

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.
6
  • 1
    > Note: I saw option user in fstab. Is there anyway without it ?
    – user9517
    Jan 10, 2017 at 7:49
  • Thanks. But as i mentioned above i already saw user option i fstab.
    – rajagopalx
    Jan 10, 2017 at 7:55
  • @RajagopalSubramanian Ok, then my answer is user must be able to mount /path/to/target. If this is not case, please post answer and/or last lines of dmesg command. Jan 10, 2017 at 9:20
  • @Hanginoninquietdesperation Users could modify system mount table either by using sudo or su or by having entry with user,noauto in /etc/fstab. Jan 10, 2017 at 9:44
  • 1
    @RajagopalSubramanian No only root can do that, as user you could only run mount with 1 argument: the target. And this must be configured (by root user) in /etc/fstab Jan 10, 2017 at 12:29
4

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
4
  • 1
    Downvoted for plagiarising without any attribution to original author: xmodulo.com/how-to-mount-nfs-share-as-regular-user.html Aug 22, 2019 at 9:47
  • @AnthonyGeoghegan no longer available. Aug 5, 2020 at 19:17
  • 1
    Thanks, @Neurotransmitter I've edited the answer to provide attribution for the plargiarised content with link to archived version of the original article. Aug 5, 2020 at 23:55
  • 1
    Nice one, thanks, in the meantime I've downvoted this answer to discourage the author from keep doing this. Aug 6, 2020 at 18:55
3

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.

1
  • I'm surprised but this actually works (well, until I have permissions problems with the actual dir). Jan 13, 2023 at 0:11
1

You can use sudo

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

You would need to add something suitable to the sudoers file e.g.

test ALL=(root) NOPASSWD: /bin/mount -o v3 192.168.30.26:/root/backup /usr/backup/

which would allow the user test to execute the exact command listed without providing a password. You should take a look at the sudo and sudoers documentation.

2
  • I actually want to mount it inside container. can I use tis inside docker container ? Bcz I have user called cinder inside the container. But cinder user is not live outside the container.
    – rajagopalx
    Jan 10, 2017 at 7:57
  • After updating /etc/sudoers file, When I switch to another user I got >>> /etc/sudoers: syntax error near line 32 <<< sudo: parse error in /etc/sudoers near line 32 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin.
    – rajagopalx
    Jan 10, 2017 at 8:08
0

This is an old post, but have you checked the permissions of /usr/backup/ ?

Most likely, your non-root user does nor have permissions to the /usr/backup folder.

Most likely they are similar to the following:

drwxr-xr-x  3 root root  4096 Aug 15 21:51 backup

Try adding a group with your user in it to that folder's permissions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .