NFS - user mapping

I have folder mounted from remote server to local:

mount -o nolock 92.xxx.xxx.xxx:/var/www/html/static/data /home/myaccount/public_html/forum/data_remote

The problem is, that local account is of UID 500 and remote is 48, so I cannot write any contents to local data /home/myaccount/public_html/forum/data_remote - because of permission denied error.

Here is my /etc/exports:

/var/www/html/static/data/      5.xxx.xxx.xxx(rw,insecure,no_root_squash)

What can I do to map properly permissions to allow myaccount to write to remote folder?


Solution 1:

You will have to change the UID to match what is on the remote server. Before doing this, make sure that your user account is not executing any processes.

usermod -u NEWUID username

Keep in mind that any files outside of your home directory will have to have their ownership changed manually. You can do that with this command on the system where you changed the UID:

find / -user OLDUID -exec chown -h username {} \;

This will give you the same UID on each system which will allow you to write to the remote directory and modify the files. It may be easier to do it on the remote machine if you aren't using it regularly and have less files on it assuming that you have the access to do so.

You can also do the same by creating a group with the same GID on each machine and adding your user to the group on the machine where you're trying to connect to the shares.

On each machine:

groupadd -g GID groupname

On the machine hosting the NFS shares:

chown :groupname /nfs/share

On the machine connecting to the shares:

usermod -aG groupname username