NFS network mount: set owner to specific account

Matthew picture Matthew · Jan 4, 2012 · Viewed 43.6k times · Source

OK, I'm seriously confused over this stuff, so really descriptive answers would be appreciated, especially if they make this whole mounting stuff less magical and more predictable.

I am trying to mount my Drobo-FS NAS with nfs to get better performance than with cifs.

The drobo is running some trimmed down linux distribution.

Inside /etc/fstab on the client machine (Ubuntu with IP: 192.168.1.150)

# Mount Drobo
192.168.1.100:/mnt/DroboFS/Shares/public /media/drobonfs nfs rw,soft,proto=tcp,users 0 0

I have unfsd installed on the drobo and access via ssh. This is the exports file on the server machine (Drobo-FS with IP 192.168.1.100):

# Allow access for client machine
/mnt/DroboFS/Shares 192.168.1.150(rw,no_root_squash)

Mounting works fine, except that the mounted files are all owned by root with most of the file permissions set to 744. The file permissions shown in the mount on the client match the actual permissions on the server. For example:

client$ sudo chmod 123 /media/drobonfs/somefile
client$ ls -l /media/drobonfs/somefile
---x-w--wx 1 root root 0 2012-01-04 14:15 /media/drobonfs/somefile

drobo$ ls -l /mnt/DroboFS/Shares/public/somefile
---x-w--wx    1 root     root            0 Jan  4 14:15 /mnt/DroboFS/Shares/public/somefile

Writing sudo in front of every command is a drag and I want to understand what is going on, so what can I do to mount it on the client machine with the owner/group set to my account instead of root?

Answer

Pieter1973 picture Pieter1973 · Jan 4, 2015

When a share is mounted the userID (UID) of the host system is mapped on the userID (UID) of the client.

On the client the mapped user (based on the userID) will become the owner of the mounted share.

Your problem is caused because the host uses other UID then the client.

You can solve this by defining a /etc/nfs.map file:

/etc/nfs.map

This will look like:

# remote local gid 500 1000 # drobo client uid 500 2003 # drobo client

So when using NFS you need to make sure there is UID/GID matching between the users on host and client. Please read the following article also: http://www.kernelcrash.com/blog/nfs-uidgid-mapping/2007/09/10/

Another great way to solve this problem is looking into the UID's on both host and client system by looking on this /etc/passwd file on both systems.

or by typing:

id tom

change the UID with:

usermod -u 10000 tom

Good luck!