I have a samba server running on a debian host so I can share an specific directory with an ubuntu 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 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 create a test file and test dir 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
Problem is that when I copy or rsync another client directory to this client samba share (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
after 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 dir 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 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.
Bessides permissions are not kept sync not matter what.
What am I missing?
kind regards