Find owner of a file in SMB mounted NAS storage
Solution 1:
You have to enable unix extensions to see the original owner of a file. Edit the SMB config file of the server:
sudo nano /etc/samba/smb.conf
And add this to your global rules:
unix extensions = yes
But note: Although its not mentioned in the documentation, this works only if you force SMB1 (NT1), so you need to add this as well:
server min protocol = NT1
And if you mount your server, you need to force SMB1 as follows:
sudo mkdir -p /mnt/smbserver/sharename
sudo mount -t cifs -o username=john,vers=1.0 //servername/sharename /mnt/smbserver/sharename
After that you will see the original linux owner of the file.
But note this as well: It transfers only the uid and not the name of the user. If the file owner has the uid 1234 and your linux client does not have any user with this uid, it will show only the number:
client$ ls -la /mnt/smbserver/sharename
total 4
drwxrwxrwx+ 1 root root 0 Sep 11 20:22 .
drwxr-xr-x 4 root root 4096 Nov 13 18:05 ..
drwxrwx---+ 1 1234 users 0 Okt 31 21:20 paper
drwxrwx---+ 1 1234 users 0 Okt 30 09:43 vanilla
And if you linked the client's username "test" to the uid 1234, it will show "test" as the file owner:
client$ ls -la /mnt/smbserver/sharename
total 4
drwxrwxrwx+ 1 root root 0 Sep 11 20:22 .
drwxr-xr-x 4 root root 4096 Nov 13 18:05 ..
drwxrwx---+ 1 test users 0 Okt 31 21:20 paper
drwxrwx---+ 1 test users 0 Okt 30 09:43 vanilla
although it could be a different username on the server:
smbserver$ ls -la /home/john/sharename
total 12
drwxrwxrwx 1 root root 34 Sep 11 22:22 ./
drwxrwxrwx 1 john users 4096 Nov 10 19:13 ../
drwxrwx--- 1 john users 4096 Nov 13 19:23 paper/
drwxrwx--- 1 john users 4096 Oct 30 11:43 vanilla/
So the best would be to have identical usernames and uids on all systems.