keep ownership of files created on a mounted NFS share

Given user (user1:u=1000,g=1000) on a ubuntu 20.04 machine,
and an nfs share defined on a WD ex2 ultra under OS5
I want that a file created by user1 on ubuntu on that share be owned by user1.
For now the file is owned by 501.

Detailed steps:
defintion of share on NAS

  • cat /etc/exports
    “/nfs/test” *(rw,all_squash,sync,no_wdelay,insecure_locks,insecure,no_subtree_check,anonuid=501,anongid=1000)

  • cat /etc/passwd
    nobody:x:501:1000:Linux User,:/home/nobody:/bin/sh

  • ls -l /nfs
    lrwxrwxrwx 1 root root 7 Apr 23 09:29 /nfs → /shares

  • ls -l /shares
    lrwxrwxrwx 1 root root 18 Apr 23 08:04 test → /mnt/HD/HD_a2/test

creation of file on ubuntu:
use user1 login

  • id user1
    uid=1000(user1) gid=1000(user1) groupes=1000(user1),4(adm),27(sudo)
    note: user1 is defined with same uid, gid on NAS and ubuntu machine.

  • cat /etc/fstab /media/test nfs rw, 0 0

  • sudo mount -a

  • ls -l /media
    drwxr-xr-x 2 root root 4096 févr. 18 22:47 test

  • create file
    touch /media/test/testfile.txt

  • verify ownership
    ls -l /media/test/testfile.txt
    -rw-rw-r-- 1 501 user1 0 avril 29 2021 testfile.txt
    drwxr-xr-x 12 root root 4096 avril 22 19:22 …/

My objective is to have user1 as file owner, not 501,
and similarly have files created by other users on the nfs share owned by their respective creator.

Is it possible to obtain such behaviour with nfs? And how?

Hi Patrick,
I have a similar challange:
I changed /etc/passwd and /etc/exportfs on the NFS server (WD MyCloud FIrmware 5.18) so that the group ID becomes 1111 instead of 1000. I also changed group permissions of existing files.
Why? I want that all Linux user which are member of the group 1111 are able to work with the files on the NFS share.

The problem is, that a reboot of the MyCloud drive will reset all those changes. In this case the GID becomes 1000 again.

Does anyone have an idea how to fix it or how to set GID=1111 permanentely?

BR, Edy

I have the exact same problem

I have a WD My Cloud ex2 with Firmware Version : 5.22.113.
For my Docker Swarm I’d like to use NFS shares instead of CIFS, because many services will fail if they are running on a CIFS share (for the locks on files and so on) but I’m not able to change the configuration of the NFS sharing to match my uid and gid.
No matter what I do I end up always getting uid and gid of nobody users on WD (501:1000) and I can create new files on the shares, delete them but I cannot edit the files, therefore for example containers that uses sqlite fails.
Are there some configurations that I’m not aware of? I’m one step closer to smash everything into piecess -.-

I may have found what’s resetting passwd. There is a default file that can’t be modified

ls -l passwd
-rwxr-xr-x 1 root root 328 May 6 17:21 passwd

I tried to check with lsattr but
lsattr: reading ./passwd: Inappropriate ioctl for device

I guess we would need to mount the path with both user_xattr and acl, am I right?
is this possible with the NAS? if yes, anyone knows the exact procedure here?