2

I want that users of my group who don't have sudo rights can mount a partition that is on a remote computer. Imagine a user has an account on several computers but a big chunk of data is lying on the hdd of a particular computer.

Is there a way that he can mount this partition on his current computer? Also the user should not be given any sudo rights.

Can I make an entry in /etc/fstab that automatically mounts the remote partition in case a specific user logs in to the computer?

  • You can mount a remote partition over NFS by putting an entry in fstab. However, this tends to cause issues(locking up) when the server is not available. Are these computers always going to be on a network with access to this server? – Dorian Aug 2 '16 at 14:45
  • Yes. The purpose is to share computers in a local area network efficiently amongst the users – mcExchange Aug 2 '16 at 14:55
  • Then an NFS share would do the trick. It's fairly straightforward and well explained here : help.ubuntu.com/lts/serverguide/network-file-system.html – Dorian Aug 2 '16 at 14:59
  • Lets say I have 4 computers. The partition to mount is on 1 of them. The user can log in on all 4 computers. Would I have to edit the fstab on all 3 computers? Isn't there a problem if they are mounted simultaneously from 3 different machines? Wouldn't it be better if the partition was only mounted when the user logs in to a machine? – mcExchange Aug 2 '16 at 15:01
  • Yes you'll have to edit the fstab on all computers, but it's a one-time thing. Then it'll mount the NFS share when it boots up. Either that or get fancy with login/logoff scripts that mount and umount the share when you login/logout. I have 2 computers at home that access the same NFS share and haven't had any issues. You could however have each computer access its own separate NFS share. So the NFS server would have 3 shares, one for each computer. You can set it up however you want. – Dorian Aug 2 '16 at 15:28
2

The easiest would be to use an NFS Share (on the "server" machine) and the automounter (autofs) on the "clients".

I assume that NFS is installed on server and client according to the first comment from Dorian.

Say, the partition to share is on /mydata, add an entry to the file /etc/exports on your server:

/mydata     *(rw,sync,no_subtree_check)

(options depend on your requirements). After calling sudo exportfs -a the partition should be exported (test with showmount -e). Same should be true after each restart of the server.

On each client, install autofs:

sudo apt-get install autofs

Edit the file /etc/auto.master to remove the comment sign from the line for /net:

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
#/misc  /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#   "nosuid" and "nodev" options unless the "suid" and "dev"
#   options are explicitly given.
#
/net    -hosts

After restarting the autofs service (sudo service autofs restart), you should be able to access the exported filesystem(s) via

/net/<servername_or_ip>/<exportname>

Eg., if your server's name is "myserver" and the exported filesystem is "/mydata", you could enter

ls /net/myserver/mydata

to see the contents of the directory.

There are a few advantages over having a static entry in /etc/fstab:

  • The NFS share is only mounted when accessed, and will be unmounted after some time of inactivity. This saves a lot of ressources and network bandwidth.
  • If you add a second share on your server (say "/myotherdata"), you do not have to add any entry on the client. Just access the path /net/myserver/myotherdata
  • If you add a second server with another share (say "/moredata" on "secondserver"), the path will be /net/secondserver/moredata without any action on the client
  • You can use the same path (/net/...) on each client, even on the server itself, if you installed and configured autofs on the server.

If you do not want to always enter /net/...., just add a link in e.g. your home directory:

ln -s /net/myserver/mydata .

Caveat:

NFS matches users/groups via the UID/GID. So the "same" user has to have the same UID on all computers, which also holds true for the groups (GID). Otherwise, access rights are mangled/corrupted. There is no problem if you have a centralized user management.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.