Score:0

Problems moving files to a samba share: permissions and ownership not persistent

US flag

I have samba running on a Ubuntu 22.04 machine so I can share an specific directory with another Ubuntu 22.04 client machine. This directory on host has no files on it.

Samba config on host is as follows:

sudo nano /etc/samba/smb.conf
[share_name]
   browseable = yes
   read only = no
   hosts allow = 192.168.0.0/16
   path = /tank/mail
   create mask = 0775
   force create mode = 0775
   force directory mode = 2775

On the Ubuntu client I have created a new directory as follows:

sudo chown -R 5000:5000 /opt/vmail-data
sudo chmod 0775 /opt/vmail-data 

Then created the persistent samba share:

sudo nano /etc/fstab
//host_ip/share_name /opt/vmail-data cifs credentials=.smbpaswd,_netdev,file_mode=0644,dir_mode=0755,rw 0 0

after sudo mount /opt/vmail-data directory is mounted.

Then I created a test file and test directory on this directory:

root:/opt/vmail-data# mkdir testdir
root:/opt/vmail-data# ls -la
total 5
drwxr-xr-x 2 root root    0 Oct 16 18:23 .
drwxr-xr-x 5 root root 4096 Oct 13 09:33 ..
drwxr-xr-x 2 root root    0 Oct 16 18:23 testdir
-rw-r--r-- 1 root root    0 Oct 16 18:23 testfile

The problem is that when I copy or rsync another client directory to this client samba share (on the same client machine) ownership and permissions get changed as follows:

source (original) directory at client:

# ls -la
total 52
drwx------ 10 5000 5000 4096 Oct 13 10:33 .
drwx------  3 5000 5000 4096 Oct 13 10:25 ..
drwx------  5 5000 5000 4096 Oct 13 09:45 .Archive
drwx------  2 5000 5000 4096 Oct 13 10:33 cur
-rw-------  1 5000 5000    0 Oct 13 09:32 dovecot-acl-list
-rw-------  1 5000 5000  608 Oct 13 10:25 dovecot-uidlist
-rw-------  1 5000 5000    8 Oct 13 09:45 dovecot-uidvalidity
-r--r--r--  1 5000 5000    0 Oct 13 09:32 dovecot-uidvalidity.63480569
drwx------  5 5000 5000 4096 Oct 13 09:45 .Drafts
drwx------  5 5000 5000 4096 Oct 13 09:45 .Junk
drwx------  2 5000 5000 4096 Oct 13 10:33 new
drwx------  5 5000 5000 4096 Oct 16 16:46 .Sent
-rw-------  1 5000 5000   36 Oct 13 09:45 subscriptions
drwx------  2 5000 5000 4096 Oct 13 10:25 tmp
drwx------  5 5000 5000 4096 Oct 13 10:04 .Trash

If I try any of above commands results are the same:

mv /path_to_source /opt/vmail-data

or

cp -a /path_to_source /opt/vmail-data

or

rsync -avr /path_to_source /opt/vmail-data

AQter any of these commands results are the same at destination path:

ls -la
total 11
drwxr-xr-x 2 root root   0 Oct 16 18:22 .
drwxr-xr-x 2 root root   0 Oct 13 10:25 ..
drwxr-xr-x 2 root root   0 Oct 13 09:45 .Archive
drwxr-xr-x 2 root root   0 Oct 13 10:33 cur
-rw-r--r-- 1 root root   0 Oct 13 09:32 dovecot-acl-list
-rw-r--r-- 1 root root 608 Oct 13 10:25 dovecot-uidlist
-rw-r--r-- 1 root root   8 Oct 13 09:45 dovecot-uidvalidity
-r--r--r-- 1 root root   0 Oct 13 09:32 dovecot-uidvalidity.63480569
drwxr-xr-x 2 root root   0 Oct 13 09:45 .Drafts
drwxr-xr-x 2 root root   0 Oct 13 09:45 .Junk
drwxr-xr-x 2 root root   0 Oct 13 10:33 new
drwxr-xr-x 2 root root   0 Oct 17 07:15 .Sent
-rw-r--r-- 1 root root  36 Oct 13 09:45 subscriptions
drwxr-xr-x 2 root root   0 Oct 13 10:25 tmp
drwxr-xr-x 2 root root   0 Oct 17 06:47 .Trash

As far as I know these commands were supposed to keep ownership and permissions from original source directory to destination, but this is not what happens. Moved files are owned by root:root and not 5000:5000 and also permissions are not the same.

If I add uid=5000,gid=5000,forceuid,forcegid to the fstab mount options files are created with 5000:5000 as owner but this is not my expected behavior. Today files on origin directory are owned by 5000:5000, but in the future this can change. Ownership should be preserved no matter what.

Besides permissions are not kept sync no matter what. What am I missing?

Marco avatar
br flag
Security on CIFS-mounts are related to the "credentials" or the settings in `smb.conf` and not to the user-id writing to it.
Rowland Penny avatar
gi flag
I am going to take a guess here, the first '5000' is for the user 'vmail' and the second '5000' is for the group 'vmail' and neither exist on the machine, which is why you have used '5000' instead of 'vmail'. I suggest you try creating the user & group on the machine.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.