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