On the setup of my house, I've decided that configuration files should be stored on the NAS. For this, the idea is that the NAS would have a share (say "config")which would be mounted on the other machines. Each application would then have its own directory in that config, so they don't overlap. Think docker volumes...

So, I have a TrueNAS and a linux machine for this exercise. I've created a dataset and tried to mount it on the linux machine, but... I used to get that the folder has 0755 permission and belongs to ... you guessed it: root:root.

Correct setup

I've used the following steps:

On the NAS

  1. Log in on the NAS and on the linux machine and identify a uid/gid combination which is not used.
  2. Create a group on the NAS with the GID identified above. I used config
  3. Create an user on the NAS with the UID from step 1 and belonging to the group created at step 2. I used an user named config too.
  4. Create a new dataset for the base directory which will be mounted and set it to belong to the new user:group. I used /mnt/Main/data/config

On the linux machine

  1. Repeat steps 1 to 3 from above
  2. Create a new directory where the NFS share would be mounted. I used /mnt/config
  3. Mount the remote folder.

I used ansible for all this:

- name: Ensure group "config" exists with correct gid
  group:
    name: config
    state: present
    gid: 9013

- name: Add "config" user with correct gid
  user:
    name: config
    comment: Configuration NFS user
    uid: 9013
    group: config
    groups:
      - docker

- name: Create config dir
  file:
    path: /mnt/config
    state: directory

- name: Unmount NAS share
  ansible.posix.mount:
    path: /mnt/config
    state: unmounted

- name: Mount NAS share
  ansible.posix.mount:
    src: '{{nas_ip}}:{{nas_share}}'
    path: /mnt/config
    opts: rw,sync,hard,intr
    state: mounted
    fstype: nfs

Where the nas_ip and nas_share are the identification of my NFS share.

Conclusion

The trick is: have matching owners on both machines

PS: In my defense, last time I mounted a NFS was about 10 years ago :)

HTH,