Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NFS network mount: set owner to specific account

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?

like image 649
Matthew Avatar asked Jan 04 '12 22:01

Matthew


People also ask

How do I change ownership of NFS mount point?

You need to change the permissions of the mounted filesystem, not of the mount point when the filesystem is not mounted. So mount /var/lib/mysql then chown mysql. mysql /var/lib/mysql . This will change the permissions of the root of the MySQL DB filesystem.

How does NFS permissions work?

Once the NFS file system is mounted read/write by a remote host, the only protection each shared file has is its permissions. If two users that share the same user ID value mount the same NFS file system, they can modify each others' files.


2 Answers

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!

like image 154
Pieter1973 Avatar answered Sep 19 '22 14:09

Pieter1973


Seems like this should work in exports on the Drobo:

/mnt/DroboFS/Shares 192.168.1.150(rw,all_squash,anonuid=NNN)

where NNN is your numeric user id on the client.

like image 22
Kyle Jones Avatar answered Sep 20 '22 14:09

Kyle Jones